firebase - How can I add button on notification FCM Android -
how add button on notification fcm , how add click event on buttons. need 2 buttons on notification
how add click event on button on notification fcm android image dismiss , answer
public class myfirebasemessagingservice extends firebasemessagingservice { private static final string tag = "fcm service"; @override public void onmessagereceived(remotemessage remotemessage) { // todo: handle fcm messages here. log.d(tag, "from: " + remotemessage.getfrom()); log.d(tag, "notification message body: " + remotemessage.getnotification().getbody()); createnotification(remotemessage.getnotification().getbody()); } private void createnotification( string messagebody) { intent intent = new intent( , resultactivity. class ); intent.addflags(intent.flag_activity_clear_top); pendingintent resultintent = pendingintent.getactivity( , 0, intent, pendingintent.flag_one_shot); intent intent1 = new intent(this, resultactivity.class); pendingintent resultintents = pendingintent.getactivity( , 0, intent1, pendingintent.flag_one_shot); uri notificationsounduri = ringtonemanager.getdefaulturi(ringtonemanager.type_notification); notificationcompat.builder mnotificationbuilder = new notificationcompat.builder(this) .setsmallicon(r.mipmap.ic_launcher) .setcontenttitle("android tutorial point fcm tutorial") .setcontenttext(messagebody) .setdefaults(notification.default_all) .setpriority(notificationcompat.priority_high) .setautocancel(true) .addaction(r.drawable.switches, "hello", resultintents) .addaction(r.drawable.call, "call", resultintent) .setsound(notificationsounduri) .setcontentintent(resultintent); notificationmanager notificationmanager = (notificationmanager) getsystemservice(context.notification_service); notificationmanager.notify(0, mnotificationbuilder.build()); } }
public class firebaseidservice extends firebaseinstanceidservice { private static final string tag = "firebaseidservice"; @override public void ontokenrefresh() { // updated instanceid token. string refreshedtoken = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "refreshed token: " + refreshedtoken); // todo: implement method send registration app's servers. sendregistrationtoserver(refreshedtoken); } private void sendregistrationtoserver(string token) { // add custom implementation, needed. } }
from api level 4.1 can add action buttons notification. see basics notification check android doc , more can check so answer , tutorial
//here in intent need provide class want open on button click in notification intent intent = new intent(this, notificationreceiveractivity.class); pendingintent pintent = pendingintent.getactivity(this, (int) system.currenttimemillis(), intent, 0); // build notification // actions fake notification noti = new notification.builder(this) .setcontenttitle("new mail " + "test@gmail.com") .setcontenttext("subject").setsmallicon(r.drawable.icon) .setcontentintent(pintent) .addaction(r.drawable.icon, "call", pintent) .addaction(r.drawable.icon, "more", pintent) .addaction(r.drawable.icon, "and more", pintent).build();
Comments
Post a Comment