Notification Bar notification A summary of issues displayed on different phones

Source: Internet
Author: User

can refer to the http://blog.csdn.net/vipzjyno1/article/details/25248021, which is written about the notice is good, but also very comprehensive, my this article is mainly to record their adaptation on the problems encountered.


The unified way to create notifications:

Notificationcompat.builder Mbuilder = New Notificationcompat.builder (mcontext);

The management of notifications is to use Notificationmanager to manage notifications, using the following: Initialize the system service to be used, and then call notify (int notifyid,notification Notification) use

Notificationmanager Mnotificationmanager= (Notificationmanager) Mcontext. Getsystemservice (Mcontext.Notification_service);

Mnotificationmanager . Notify (Mbuilder.build ());


Next describe the use problem in Builder: (The following model zte-u807 (Brush machine DUI Desktop), Samsung A5, nut phone for testing)

1. not set on phone Setsmallicon Will not show notifications , but Samsung and ZTE phones will alert you to vibrations

Mbuilder. Setsmallicon (r.drawable. Notify_icon ). Setlargeicon (Bigicon);


2, different phone set setsmallicon location display inconsistent

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/wyfs02/M01/8C/E2/wKiom1h8dr7TBDcdAAAHA5aN-O4332.png "title=" 11.png "alt=" Wkiom1h8dr7tbdcdaaaha5an-o4332.png "/>

(1) both are set mbuilder. Setsmallicon (r.drawable. Notify_icon ). Setlargeicon (Bigicon);

nut Cell Phone display: Ticker notification shows a small icon SmallIcon , a area display app icon, e area shows small icon SmallIcon

Samsung phone display: Ticker notification shows a small icon, a area shows a large icon, the e area is a small icon.

ZTE Mobile Phone display: Ticker notification shows a small icon (centercrop), a area is a large icon, the e area is a small icon (but very large, the area of the icon is too large, not suitable for the match)

(2) set only Mbuilder. Setsmallicon (r.drawable. Notify_icon )

nut Cell Phone display: Ticker notification shows a small icon SmallIcon , a area shows the app icon, the E area is not displayed.

Samsung phone display: Ticker notification shows a small icon, a area shows a small icon, the E area is not displayed.

ZTE Mobile Phone display: Ticker notification shows a small icon (centercrop), a area shows a small icon, the E area is not displayed.

3, custom notification ( Note that the contents of the best not more than two lines, remember to omit )

/** *  Custom View Notification  */public void shownotifyconfirm (String title,string content, String ticker)  {    //  Set remoteviews  remoteviews  first Viewcustom = new remoteviews (Mcontext.getpackagename (), r.layout.view_custom);   //   Set the resource picture   viewcustom.setimageviewresource (R.id.custom_icon, r.drawable.icon) for the ID of the corresponding ImageView ;   // view_custom.setint (R.id.custom_icon, "Setbackgroundresource", R.drawable.icon);   Viewcustom.settextviewtext (R.id.tv_custom_title, title);   viewcustom.settextviewtext (R.id.tv_ custom_content,content);   viewcustom.settextviewtext (R.id.tv_custom_time,refformatnowdate ());   //  Set time display   viewcustom.setviewvisibility (r.id.tv_custom_time, view.gone);   Notificationcompat.builder mbuilder = new builder (Mcontext);   Mbuilder.setautocancel (True)        .setticker (Ticker)     .setsmallicon (R.drawable.btn_prev)//Small Icons      .setcontent (Viewcustom)     //.setcontentintent (GetDefalutIntent ( Notification.flag_auto_cancel)     .setwhen (System.currenttimemillis ())//notification of the time generated, will be displayed in the notification message     .setpriority (Notification.priority_default)//Set the notification priority     . Setongoing (false);//Not in progress  ,true for ongoing   effects and. Flag;   mnotificationmanager.notify (105,  Mbuilder.build ());}


The display results are analyzed as follows:

nut Cell Phone display: Ticker notification shows the small icon SmallIcon , the D area is the app icon, the purple area is the app name, click the drop-down arrow to close or expand a new notification. The following area is a custom layout area.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s2.51cto.com/wyfs02/M01/8C/DE/wKioL1h8dtbjWidkAAAaU17131w734.png "title=" 12.png "alt=" Wkiol1h8dtbjwidkaaaau17131w734.png "/>

Samsung phone display: Ticker notification shows a small icon, a area is a custom icon, regardless of the settings do not set large icons do not display large icons .

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s2.51cto.com/wyfs02/M02/8C/E2/wKiom1h8dunTYC-_AAAFn6RX2sE717.png "title=" 13.png "alt=" wkiom1h8duntyc-_ Aaafn6rx2se717.png "/>

ZTE Mobile Phone display: Ticker notification shows a small icon (centercrop), a area shows a large icon, b area is a custom icon. ( If you do not set a large icon, there is no display of a area , only the display of the custom layout, C area generally two lines will be OK, related to the adaptation problem)

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s2.51cto.com/wyfs02/M02/8C/DE/wKioL1h8dvvBOFogAAAG9XZIoC8315.png "title=" 14.png "alt=" Wkiol1h8dvvbofogaaag9xzioc8315.png "/>

4, click on the notification bar, through receiver processing jump after the things ( in the manifest file registration must add Export=true attributes, or most of the phone can not receive onreceive)

/** *  Show notification Bar Click Jump to process  **/public void showintentreceivernotify in receiver (string title , String content,string ticker,string pid)  {     Notificationcompat.builder mbuilder = initnotify ();   mbuilder.setautocancel (True)       .setcontenttitle (title)     .setcontenttext (content)     .setticker (ticker);   intent clickintent = new intent ( Mcontext, clicknotifyreceiver.class);   clickintent.setaction (" Com.qihoo.gamecenter.pluginapk.ClickNotifyReceiver.click ");   clickintent.putextra (" Pushid ",  pid );   pendingintent pendingintent = pendingintent.getbroadcast (mContext, 0,  clickintent, pendingintent.flag_update_current);   mbuilder.setcontentintent (PendingIntent);              &nbSp;mnotificationmanager.cancel (  mnotificationmanager.notify); (110, mbuilder.build ());} 


At the time of the value,setcontentintent (pendingintent Intent) This method, Pendingintent can set the number of executions, mainly used for remote service communication, Alarm, notification, Launcher, SMS.

notification supports multiple intent to respond to click events, eliminate events, and handle full-screen events for emergencies, etc. setcontentintent (pendingintent intent) to handle so many of these events.

The bit identifier for the pendingintent:

Flag_one_shot indicates that the returned pendingintent can only be executed once and automatically canceled after execution

Flag_no_create indicates that if the description of the pendingintent does not exist, the corresponding pendingintent is not created, but returns null

Flag_cancel_current indicates that the corresponding pendingintent already exists, cancels the former and then creates a new pendingintent, which facilitates the data to remain up-to-date and can be used for communication scenarios of instant communication

Flag_update_current represents the updated pendingintent


The use of specific pendingintent, you can refer to http://blog.csdn.net/vipzjyno1/article/details/25248021, which is written about the notice is good, but also very comprehensive, My essay is mainly about documenting my problems with adaptation.

Note: Click on the notification bar to handle the post-jump events via receiver, broadcast and receive broadcasts here we don't do a detailed description.


This article is from the "Vivian Son" blog, please be sure to keep this source http://9550674.blog.51cto.com/9540674/1892298

Notification Bar notification A summary of issues displayed on different phones

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.