Android Umeng PushService

Source: Internet
Author: User

Android Umeng PushService

Public class PushServices extends UmengBaseIntentService {private PushAgent mPushAgent; private vertex service; private ScheduledFuture scheduledFuture; private int I = 1; private Handler handler = new Handler () {public void handleMessage (android. OS. message msg) {Toast. makeText (getApplicationContext (), "scheduled:" + msg. what, Toast. LENGTH_SHORT ). show () ;};}; @ Overridepublic void onCreate (){// TODO Auto-generated method stubsuper. onCreate (); try {timeTask ();} catch (InterruptedException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (ExecutionException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}/ ***** @ Title: timeTask * @ Description: TODO Scheduled Update task, one set of scheduled uploads * @ return void */public void timeTask () throws InterruptedException, ExecutionException {// TODO Aut O-generated method stubif (service = null) {service = Executors. newScheduledThreadPool (1);} if (scheduledFuture = null) {scheduledFuture = service. scheduleAtFixedRate (new UploadData (), 0, 5, TimeUnit. SECONDS) ;}@ Overrideprotected void onMessage (Context context, Intent intent) {// TODO Auto-generated method stubsuper. onMessage (context, intent); try {String message = intent. getStringExtra (BaseConstan Ts. MESSAGE_BODY); if (StringUtils. isEmpty (message) {return;} UMessage msg = new UMessage (new JSONObject (message); if (msg! = Null) {mPushAgent = PushAgent. getInstance (context); UmengMessageHandler messageHandler = new UmengMessageHandler (); messageHandler. dealWithNotificationMessage (context, msg); umengnotifclickclickhandler icationclickhandler = new umengnotifnotifclickhandler (); mPushAgent. setMessageHandler (messageHandler); mPushAgent. setnotifclickclickhandler (icationicationclickhandler); UTrack. getInstance (contex T ). trackMsgClick (msg) ;}} catch (Exception e) {}}@ Overridepublic void onDestroy () {// TODO Auto-generated method stubsuper. onDestroy (); if (scheduledFuture! = Null) {scheduledFuture. cancel (true); scheduledFuture = null ;}// upload task public class UploadData implements Runnable {@ Overridepublic void run () {// TODO Auto-generated method stubi ++; message message = Message. obtain (); message. what = I; handler. sendMessage (message );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.