如何区分Notifications
并将它们传递给不同的活动?在下面的方法中,第三个parameter(String tag
) 值是从中检索的onMessage()
,其中包含一个值。根据该值,我想区分打开哪个 URL,例如 Google 或 Facebook。在我在下面的“if”条件中包含意图代码后,应用程序终止。请帮忙
private static void generateNotification(Context context, String message,
String tag) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
message, when);
String title = context.getString(R.string.app_name);
Log.d("GCM", "Tag Value " + tag);
if (tag.equals("one")) {
// pass to a different activity
notificationIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.com"));
}
if (tag.equals("two")) {
// pass to a different activity
notificationIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.facebook.com"));
}
// set intent so it does not start a 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;
notificationManager.notify(0, notification);
}