android notification opens fragment from Activity -
hello in application need generate notification.
for have done
private void generatenotification(string message) { mnotificationmanager = (notificationmanager) .getsystemservice(context.notification_service); notificationcompat.builder mbuilder = new notificationcompat.builder( this) /* .setsmallicon(r.drawable.ic_launcher) */ .setsmallicon(r.drawable.app_icon) .setcontenttitle(getresources().getstring(r.string.app_name)) .setstyle( new notificationcompat.bigtextstyle().bigtext(message)) .setticker(message).setcontenttext(message).setautocancel(true); // play default notification sound mbuilder.setdefaults(notification.default_sound | notification.flag_auto_cancel | notification.default_lights); /* * pendingintent contentintent = pendingintent.getactivity(this, 0, new * intent(this, recentchatlist.class), 0); */ /* * pendingintent contentintent = pendingintent.getactivity(this, 0, new * intent(this, dashboardactivity.class), 0); */ pendingintent contentintent = pendingintent.getactivity(this, 0, new intent(this, dashboardactivity.class), 0); mbuilder.setcontentintent(contentintent); mnotificationmanager.notify(notification_id, mbuilder.build()); }
and in dashboardactivity
if (global.getopen_which_fragment_on_notification().contains( "single message")) { global.setopen_which_fragment_on_notification(""); fragmentmanager fragmentmanager1; // on first time display view first item fragment fragment1 = null; fragment1 = new chatfragment(); if (fragment1 != null) { fragmentmanager1 = getfragmentmanager(); fragmentmanager1.begintransaction() .replace(r.id.frmlayout, fragment1).commit(); txtheadertitle.settext("chat"); } } else { global.setopen_which_fragment_on_notification(""); fragmentmanager fragmentmanager1; // on first time display view first item fragment fragment1 = null; fragment1 = new mygroupsfragment(); if (fragment1 != null) { fragmentmanager1 = getfragmentmanager(); fragmentmanager1.begintransaction() .replace(r.id.frmlayout, fragment1).commit(); txtheadertitle.settext("group chat"); } }
this works properly, mean when single chat notification arrives opens proper fragment(chatfragment) when group notification again opens chat fragment not opens group fragment missed in code
thanks in advance
pragna
Comments
Post a Comment