2
有没有一种方法可以通过单击通知或正常启动来跟踪确定Android应用程序是否已启动?通过点击通知来确定应用程序是否已启动的方法
有没有一种方法可以通过单击通知或正常启动来跟踪确定Android应用程序是否已启动?通过点击通知来确定应用程序是否已启动的方法
您可以将extra放入您用于为通知创建PendingIntent的Intent中。
// 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);
在定义您在通知中添加的意图时,请添加一些布尔标志作为附加。然后在主要活动开始检查意图是否包含额外的内容。
谢谢你,我不得不确保设置标志 –