2013-08-23 25 views

回答

4

您可以将extra放入您用于为通知创建PendingIntent的Intent中。

official guide

// Instantiate a Builder object. 
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
// Creates an Intent for the Activity 
Intent notifyIntent = 
     new Intent(new ComponentName(this, ResultActivity.class)); 
// Sets the Activity to start in a new, empty task 
notifyIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); 
// Creates the PendingIntent 
PendingIntent notifyPendingIntent = 
     PendingIntent.getActivity(
     this, 
     0, 
     notifyIntent 
     PendingIntent.FLAG_UPDATE_CURRENT 
); 

// Puts the PendingIntent into the notification builder 
builder.setContentIntent(notifyPendingIntent); 
// Notifications are issued by sending them to the 
// NotificationManager system service. 
NotificationManager mNotificationManager = 
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
// Builds an anonymous Notification object from the builder, and 
// passes it to the NotificationManager 
mNotificationManager.notify(id, builder.build()); 

只需添加notifyIntent.putExtra("fromNotification", true);

+0

谢谢你,我不得不确保设置标志 –

4

在定义您在通知中添加的意图时,请添加一些布尔标志作为附加。然后在主要活动开始检查意图是否包含额外的内容。

相关问题