java - Use notification ID to change logo & text -
i'd know how applications facebook change notification title & logo depending on content.
for example, in facebook, if tagged title & logo.
i assume should possible notify create unique notification. though can't find clear examples this.
my generatenotification:
private static void generatenotification(context context, string message, string url) { int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, showchange.class); notificationintent.putextra ("url",url); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel; // play default notification sound notification.defaults |= notification.default_sound; //notification.sound = uri.parse("android.resource://" + context.getpackagename() + "your_sound_file_name.mp3"); // vibrate if vibrate enabled notification.defaults |= notification.default_vibrate; notificationmanager.notify(0, notification); }
it should this:(this code modifications)
public static void generatenotification(context context, string message, string url,int icon_from_drawable) { int icon = icon_from_drawable;
long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, showchange.class); notificationintent.putextra ("url",url); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel; // play default notification sound notification.defaults |= notification.default_sound; //notification.sound = uri.parse("android.resource://" + context.getpackagename() + "your_sound_file_name.mp3"); // vibrate if vibrate enabled notification.defaults |= notification.default_vibrate; notificationmanager.notify(0, notification);
}
if targeting app api level>=11, use notification.builder refer here : http://developer.android.com/reference/android/app/notification.builder.html 1 more point above code keep updating same notification object because notify method of notification manager taking same id i.e 0, same object of notification updated.
Comments
Post a Comment