Jpush Embedding Engineering
Detailed website
Customizing the notification bar
Customize receiver First
<receiver android:name= "Your receiver" android:enabled= "true" > <intent-filter> < Action android:name= "Cn.jpush.android.intent.REGISTRATION"/> <action android:name= " Cn.jpush.android.intent.MESSAGE_RECEIVED "/> <action android:name=" Cn.jpush.android.intent.NOTIFICATION_RECEIVED "/> <action android:name=" Cn.jpush.android.intent.NOTIFICATION_OPENED "/> <category android:name=" You package name "/> </intent-filter></receiver>
private static final String TAG = "Myreceiver"; @Overridepublic void OnReceive (context context, Intent Intent) {Bundle bund Le = Intent.getextras (), if (JPushInterface.ACTION_REGISTRATION_ID.equals (Intent.getaction ())) {log.i (TAG, " Jpush User Registration successful ");} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals (Intent.getaction ())) {log.i (TAG, "accept the push down custom message"); Receivingnotification (context, bundle);} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals (Intent.getaction ())) {log.i (TAG, "accept notifications to push Down");} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals (Intent.getaction ())) {LOG.I (TAG, "user clicked to open the Notification"); Opennotification (context, bundle);}}
Customizing the Notification notification Bar in receivingnotification ()
private void Receivingnotification (context context, bundle bundle) {Notificationmanager manager = (Notificationmanager) Context.getsystemservice (Context.notification_service); String message = bundle.getstring (jpushinterface.extra_message); String Extras = bundle.getstring (Jpushinterface.extra_extra);//Use notification// Display of content using broadcasts or notifications Notificationcompat.builder Builder = new Notificationcompat.builder (context); Builder.setcontenttext (message). Setsmallicon (r.drawable.notification_icon_2). Setcontenttitle (Jpushinterface.extra_title); Builder.setdefaults (Notification.default_sound); Manager.notify (1,builder.build ());}
I tried to change the icon in the notification bar, various methods have been tried, the document looked at countless times, found that the icons are immutable, and always the same as the app icon.
with drop-down effect
There is also a custom notification bar with a drop-down effect. This is the official website.
Layout file Customer_notitfication_layout.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" Horizontal " > <imageview android:id= "@+id/icon" android:layout_width= "wrap_content" android:layout_height= "Wra P_content "/> <linearlayout android:layout_width=" wrap_content "android:layout_height=" Wrap_conte NT "android:orientation=" vertical "android:layout_marginleft=" 10dip "> <textview android: Id= "@+id/title" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text Color= "#286CA6" android:textsize= "20sp"/> <textview android:id= "@+id/text" Android:layo Ut_width= "Wrap_content" android:layout_height= "wrap_content" android:textcolor= "#6FA45E" Android:te Xtsize= "16sp"/> </lInearlayout></linearlayout>
Initialize notification effects
Custompushnotificationbuilder builder = new Custompushnotificationbuilder (Mainactivity.this, R.layout.customer_ Notitfication_layout,r.id.icon, R.id.title, r.id.text);//Specify custom Notification layoutbuilder.statusbardrawable = r.drawable.notification_icon;//Specifies the top level status bar small icon builder2.layouticondrawable = r.drawable.notification_icon;// Specifies the notification icon that appears when the drop-down status bar is Jpushinterface.setpushnotificationbuilder (1, builder1);
there is a method in this builder.statusbardrawable, this setting is a status bar icon, not the drop-down interface that. When you come to the notification, the top of the phone will scroll to indicate the message. The icon set here is just the notification at the top, not the one in the red box.
This brings down the effect
a simple version provided by the official website
There is a simple version, but also the official website Demo,mark a bit. Set as default to send notifications
Basicpushnotificationbuilder builder2 = new Basicpushnotificationbuilder (mainactivity.this); builder2.statusbardrawable = R.drawable.logo;builder2.notificationflags = Notification.flag_auto_cancel; Set to Auto-disappear Builder2.notificationdefaults = notification.default_sound| Notification.default_vibrate | Notification.default_lights; Set to ring and vibrate to Jpushinterface.setdefaultpushnotificationbuilder (BUILDER2); Jpushinterface.setpushnotificationbuilder (2, Builder2);
Setpushnotificationbuilder (2, Builder2); sets the style number of the Builder2 to 2, sending the specified number when sent.
Jpush website Android API
[Android] Jpush Customizing the Notification bar