android - Sending data to a notification -


i'm working on app can make own notifications (just fun). can customize them in (almost) way.

my problem is: don't know how data main activity notification service.

this how intent i'm using right looking like:

intent startnotificationserviceintent = new intent(mainactivity.this, notification.class);             startnotificationserviceintent                     .putextra("title", title)                     .putextra("text", text)                     .putextra("millis", millis)                     .putextra("isimportant", isimportant);              startservice(startnotificationserviceintent); 

and onstartcommand right now:

@override public int onstartcommand(intent intent, int flags, int startid) {     displaynotification(/*currently empty*/);     stopself();     return super.onstartcommand(intent, flags, startid); } 

and method (displaynotification) i'm using create notification:

private void displaynotification(string title, string text, long vibrationlongmillis, boolean isimportant) {     intent notificationintent = new intent(this, mainactivity.class);     pendingintent notificationpendingintent = pendingintent.getactivity(this, 0, notificationintent, 0);      notificationcompat.builder notification = new notificationcompat.builder(this)             .setcontenttitle(title)             .setcontenttext(text)             .setsmallicon(r.drawable.attention)             .setcolor(getresources().getcolor(r.color.colorprimary))             .setvibrate(new long[]{0, vibrationlongmillis, vibrationlongmillis, vibrationlongmillis})             .setsound(uri)             .setcontentintent(notificationpendingintent)             .setautocancel(true)             .setpriority(notificationcompat.priority_default)             .setstyle(new notificationcompat.bigtextstyle().bigtext(text));      if (isimportant) {         notification.setpriority(notificationcompat.priority_high);     }       notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service);     notificationmanager.notify(notification_id, notification.build());  } 

you need pass information in intent (as doing it) , read in service this:

@override public int onstartcommand(intent intent, int flags, int startid) {     string title = intent.getstringextra("title");     /* here same other parameters */     displaynotification(title, text, vibrationlongmillis, isimportant);     stopself();     return super.onstartcommand(intent, flags, startid); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -