在我的应用程序中,我已经为朋友即将到来的生日创建了通知。如果有多个朋友的生日,它将打开多个通知。 我的问题: - 如果我点击第一个通知,它必须触发一个Activity.Suppose Activity1 如果我要点击另一个通知,它必须触发另一个活动,比如活动2。
有没有办法做到这一点。请帮助我。谢谢。
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = context.getResources();
// Creates an explicit intent for an Activity in your app
Intent resultIntent1 = new Intent(context, FragmentActivity1.class);
String pass = name;
resultIntent1.setData(new Uri.Builder().scheme("data")
.appendQueryParameter("text", "my text").build());
resultIntent1.putExtra("title", pass);
resultIntent1.putExtra("uid", i);
TaskStackBuilder stackBuilder1= TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder1.addParentStack(FragmentActivity1.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder1.addNextIntent(resultIntent1);
PendingIntent resultPendingIntent1 = stackBuilder1.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.cake)
.setLargeIcon(
BitmapFactory.decodeResource(res,
R.drawable.cake))
.setTicker("BirthDay " + name)
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setContentTitle(name)
.setContentIntent(resultPendingIntent1);
Notification n = builder.build();
n.flags = Notification.FLAG_NO_CLEAR;
nm.notify(i++, n);
`