0

我有一个简单的应用程序,它根据您按下的三个按钮之一显示 android 通知。

狗、猫或老鼠

如果您按狗,则显示“狗”的通知。如果您按 cat,则会显示“Cat”的通知。如果您按下鼠标,则会显示“鼠标”的通知。

当您单击通知时,它只会将我带到我的主要活动(再次使用三个按钮)。我希望它带我进入一个单独的活动,它将读取点击了哪些通知,并将通知中的文本设置为 textView。

关于如何做到这一点的任何想法?

4

1 回答 1

2
NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());

来源:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions

于 2012-10-16T01:02:36.750 回答