我正在制作一个Android应用程序。我有一个问题,就是我的MainActivity可以通过3种方式创建:
如何检查通知点击何时开始?
通知代码:
private void createNotification()
{
Log.d("service createNotification",MainActivity.TAG);
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this,MainActivity.class);
intent.putExtra(AppNames.IS_NOTIFICATION_INTENT,true);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(this.getString(R.string.notification_title))
.setContentText(this.getString(R.string.notification_text))
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher);
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(AppNames.APP_NOTIFICATION, builder.getNotification());
}
添加
intent.putExtra("started_from","notification");
对于从通知启动意图的代码,对于其他 startActivity 调用也是如此,只需更改值,然后在您的活动中
String startedFrom = getIntent().getStringExtra("started_from");
有关更多信息,请参阅此问题:如何从 Android 上的 Intent 获取额外数据?
要确定哪个服务或广播接收器在您的应用程序中充当通知蹦床,请查看以下终端命令的输出:
adb shell dumpsys activity service \com.android.systemui/.dump.SystemUIAuxiliaryDumpService
输出包含文本“NotifInteractionLog”。此部分包含识别因通知点击而启动的组件所需的信息。