2

在我的应用程序中,我为即将到来的生日的朋友创建了通知。如果有多个朋友的生日,它将打开多个通知。我的问题:-如果我单击第一个通知,它必须触发一个 Activity。假设 Activity1 如果我要单击另一个通知,它必须触发另一个 Activity,比如说 Activity2。

有什么办法可以做到这一点。请帮助我。谢谢。

        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);

`

4

0 回答 0