<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.day_2015_umengpush" Android:versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= "8" Android: targetsdkversion= "One"/> <!--umengpush ==========================================================--< Uses-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= " Android.permission.ACCESS_NETWORK_STATE "/> <uses-permission android:name=" android.permission.READ_PHONE_ State "/> <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE "/> <uses-permission Andro Id:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name= " Android.permission.WAKE_LOCK "/> <uses-permission android:name=" Android.permission.VIBRATE "/> <uses-pe Rmission android:name= "Android.permission.WRITE_SETTINGS"/> <!--"optional" as neededAdd-<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/> <!--umengpush ===== =====================================================--<application android:name= "com.panpass.main.MyAp Plication "android:allowbackup=" true "android:icon=" @drawable/ic_launcher "android:label=" @string/app _name "Android:theme=" @style/apptheme "> <activity android:name=" Com.panpass.main.MainActiv ity "android:icon=" @drawable/ic_launcher "android:label=" @string/app_name "Android:screen orientation= "Portrait" > <intent-filter> <action android:name= "android.intent.action . MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filte r> </activity> <activity android:name= "Com.panpass.main.OpenActivity" Android oid:icon= "@drawable/ic_Launcher "android:label=" @string/app_name "android:screenorientation=" Portrait "> </act ivity> <service android:name= "Com.panpass.pushservice.PushService"/> <!--umengpush =========== ===============================================--<meta-data android:name= "Umeng_channel" Android:value= "Umeng" > </meta-data> <meta-data android:name= "Umeng_appkey" Android:value= "54b778aefd98c523200005f6" > </meta-data> <meta-data Android:nam E= "Umeng_message_secret" android:value= "e75bee338ac1123f7f46260cfc2828db" > </meta-data> <receiver android:name= "Com.umeng.message.NotificationProxyBroadcastReceiver" android:exported= " False "> </receiver> <receiver android:name=" Com.umeng.message.RegistrationReceiver "> <intent-filter&gT <action android:name= "Android.net.conn.CONNECTIVITY_CHANGE"/> </intent-filter> <inte nt-filter> <action android:name= "Android.intent.action.PACKAGE_REMOVED"/> <data Android:scheme= "Package"/> </intent-filter> <!--"optional" add-on as needed-<inte nt-filter> <action android:name= "Android.intent.action.BOOT_COMPLETED"/> </intent-f ilter> </receiver> <receiver android:name= "Com.umeng.message.UmengBroadcastReceiver" > <intent-filter> <action android:name= "Org.agoo.android.intent.action.RECEIVE"/> </intent-filter> <intent-filter> <action android:name= "Com.example.day_2015_ume Ngpush.intent.action.COMMAND "/> </intent-filter> <intent-filter> < Action Android:name= "org.agoo.android.intent.action.RE_ELECTION_V2"/> </intent-filter> </receiver > <service android:name= "Com.umeng.message.UmengService" android:exported= "true" android:process= ": Umengservice_v1" > <intent-filter> <action android:name= "com. Example.day_2015_umengpush.intent.action.START "/> </intent-filter> <intent-filter> <action android:name= "Com.example.day_2015_umengpush.intent.action.COCKROACH"/> </inten t-filter> <intent-filter> <action android:name= "Org.agoo.android.intent.action.PING" /> </intent-filter> </service> <service android:name= "org.android.a Goo.service.ElectionService "android:exported=" true "android:process=": Umengservice_v1 "> <intent-filter> <action android:name= "org.agoo.android.intent.action.ELECTION_V2"/> </intent-filter> </s ervice> <service android:name= "Com.umeng.message.UmengIntentService"/> <!--V1.3.0 added service, responsible for Download notification RESOURCES-<service android:name= "Com.umeng.message.UmengDownloadResourceService"/> <!--Umeng Push ==========================================================-</application></manifest>
Package Com.panpass.main;import Com.example.day_2015_umengpush. R;import Com.umeng.message.pushagent;import Com.umeng.message.utrack;import Com.umeng.message.UmengMessageHandler ; Import Com.umeng.message.umengnotificationclickhandler;import Com.umeng.message.entity.umessage;import Android.app.application;import Android.app.notification;import Android.content.context;import Android.os.Handler; Import Android.support.v4.app.notificationcompat;import Android.widget.remoteviews;import android.widget.Toast; public class MyApplication extends application {private pushagent mpushagent = null; @Overridepublic void OnCreate () {Mpush Agent = Pushagent.getinstance (this); Mpushagent.setdebugmode (true); Umengmessagehandler UMH = new Umengmessagehandler () {@Overridepublic void Dealwithcustommessage (Final context context, Final Umessage msg) {New Handler (Getmainlooper ()). Post (new Runnable () {@Overridepublic void run () {utrack.getinstance ( Getapplicationcontext ()). Trackmsgclick (msg); Toast.maketext (Context, MSG.Custom, Toast.length_long). Show ();}}); @Overridepublic Notification getnotification (context context, Umessage msg) {switch (msg.builder_id) {Case 1: Notificationcompat.builder Builder = new Notificationcompat.builder (context); Remoteviews Mynotificationview = new Remoteviews (Context.getpackagename (), R.layout.notification_view); Mynotificationview.settextviewtext (R.id.notification_title, Msg.title); Mynotificationview.settextviewtext ( R.id.notification_text, Msg.text); Mynotificationview.setimageviewbitmap (R.id.notification_large_icon, Getlargeicon (context, msg)); Mynotificationview.setimageviewresource (R.id.notification_small_icon, GetSmallIconId (Context, MSG)); Builder.setcontent (Mynotificationview); Notification mnotification = Builder.build ();//due to the bug of Android V4 pack, In the 2.3 and following systems, builder created the notification, and did not set RemoteView, it is necessary to add this code Mnotification.contentview = Mynotificationview;return mnotification;default://default is 0, if the fill builder_id does not exist, also use the default. Return super.getnotification (context, MSG);}}; Mpushagent.setmessAgehandler (UMH);/** * This handler is called in Broadcastreceiver, so * if you need to start ACTIVITY, add Intent.flag_activity_new_task * It's actually a callback * /umengnotificationclickhandler Notificationclickhandler = new Umengnotificationclickhandler () {@Overridepublic void Dealwithcustomaction (context context, Umessage msg) {Toast.maketext (context, Msg.custom, Toast.length_long). Show ();}}; Mpushagent.setnotificationclickhandler (Notificationclickhandler);}}
Package Com.panpass.main;import Android.app.activity;import Android.os.bundle;import android.os.handler;import Android.os.message;import Android.widget.textview;import Com.example.day_2015_umengpush. R;import Com.umeng.message.pushagent;import Com.umeng.message.umengregistrar;public class MainActivity extends Activity {private TextView mtextview;private pushagent mpushagent = null;private static final int get_device_token = 1;pri vate Handler Mhandler = new Handler () {public void Handlemessage (android.os.Message msg) {switch (msg.what) {case Get_devic E_TOKEN:mTextView.setText (string.valueof (msg.obj)); break;default:break;};}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Mtextview = (TextView) Findviewbyid (R.id.text_view);////pushagent mpushagent = Pushagent.getinstance (this);//mpushagent.enable (),//pushagent.getinstance (this). Onappstart ();//string Device_ token = Umengregistrar.getregistrationid (this);StartService (New Intent (This,pushservice.class)); mpushagent = Pushagent.getinstance (this); Pushagent.getinstance (This). Onappstart (); mpushagent.enable (); GetToken (); private void GetToken () {Mhandler.post (new Runnable () {@Overridepublic void run () {String Device_token = Umengregistrar.getregistrationid (Mainactivity.this); Message msg = Mhandler.obtainmessage (); msg.what = Get_device_token;msg.obj = Device_token;mhandler.sendmessage (msg);}});} }
To customize the notification style, you must have:
=====umeng--->push======