我的新闻应用程序在后台运行,如果新闻有任何更新,状态栏中会显示一条通知。
如何判断我的应用是点击通知打开还是直接打开?
最佳答案
试试这个
当您使用 Boundle 对象启动它们时,您可以向您的起始 Intent 添加一些额外的数据。因此,当您从通知创建 PendingIntent 时,添加以下内容。
Boundle b=new Bundle();
b.putString("from","fromNotification");
intent.putExtras(b);
然后在您的开始 Activity 中检查。
Bundle b=getIntent().getExtras();
String startedForm=b.getString("form");
现在你可以决定它从哪里来了。如果 startedFrom
是 null
那么它已经直接开始或者如果它是“fromNotification
”然后它已通过通知开始
关于android - 通知的 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9836418/