Android sends multiple notification

Source: Internet
Author: User

Android sends multiple notification  , <span style= "font-size:11.8181819915771px; font-family:arial, Helvetica, Sans-serif; " The ID of the >pendingintent is important. </span>
public void AddNotification (Jsonarray args, Callbackcontext callbackcontext) throws jsonexception {//notification_id = Args.getint (6); notification_id = (int) (Math.random () *10000); try {nm = (Notificationmanager) cordova.getactivity (). Getsystemservice ( Context.notification_service); Intent Intent = new Intent (CX, Cordova.getactivity (). GetClass ()); Intent.putextra (" ClickAction ", args.getstring (4)); String clickactionparams = Args.getjsonobject (5). toString (); Intent.putextra ("Clickactionparams", Clickactionparams ); Pendingintent pintent = pendingintent.getactivity (cx, <strong><span style= "color: #ff0000;" >notification_id</span></strong>, intent,pendingintent.flag_update_current); int version = Android.os.Build.VERSION.SDK_INT; Notification notify;//If the version number is greater than 15. That is, the Notification.builder method, if the version number is less than 15, that is, using the old method, avoid similar manaslu phone problems if (Version >) {notify = New Notification.builder (CX)//set to turn on the notification, the notification automatically disappears. Setautocancel (TRUE)//sets the notification prompt information displayed in the status bar. Setticker (args.getstring (0)) Sets the icon for the notification. SetsmallicOn (R.drawable.icon)//sets the caption of the notification content. Setcontenttitle (args.getstring (0))//Set the notification content. Setcontenttext (args.getstring (1) + notification_id). Setwhen (System.currenttimemillis ())//Set notification to start the program's Intent.setcontentintent (pintent). build (); else {notify = new Notification (R.drawable.icon, args.getstring (0), System.currenttimemillis ()); Notify.setlatesteventinfo (CX, args.getstring (0), args.getstring (1), pintent);} Send notification nm.notify (notification_id, notify);//notification displays x seconds after automatically clearing if (Args.getboolean (2)) {Disappeartime = Args.getlong (3); Handler Handler = new Handler () handler.postdelayed (new Runnable () {public void run () {//TODO auto-generated method stubn M.cancel (notification_id);}}, Disappeartime);}} catch (Jsonexception e) {e.printstacktrace ();} catch (Exception e) {e.printstacktrace ()}}

Android sends multiple notification

Related Article

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.