Jir*_*ong 19 android push-notification
通常,当我在通知栏上有通知消息并单击它时.它打开该邮件的已注册应用程序.
在Startup的活动中,如何确定App是否从中打开?
更好的是如何在OnCreate()方法上检索通知的id?
更新:来自@Ovidiu - 这是我的putExtra推送代码
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, Startup.class);
notificationIntent.putExtra("JOBID", jobId);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.contentIntent = contentIntent;
mNotificationManager.notify(jobId, notification);
Run Code Online (Sandbox Code Playgroud)
并在主要活动"Startup.java"代码是
Intent intent = this.getIntent();
if (intent != null && intent.getExtras() != null && intent.getExtras().containsKey("JOBID")) {
int jobID = this.getIntent().getExtras().getInt("JOBID");
if (jobID > 0) {
}
}
Run Code Online (Sandbox Code Playgroud)
intent.getExtras()始终返回null.结果,我需要传递PendingIntent.FLAG_ONE_SHOT.它现在传递!!
Ovi*_*tcu 18
您需要putExtra(ID_KEY,id)在创建Intent启动应用程序时使用,并且在您的onCreate()方法中,您可以使用它getIntent().getExtras().getInt(ID_KEY);来检索传递的ID integer.
Start Activity代码就是这样的,否则一旦它来自GCM通知,从那时每次Activity都来自Recent list,它会说它来自GCM通知,这是错误的.
Intent intent = this.getIntent();
if (intent != null && intent.getExtras() != null && intent.getExtras().containsKey("JOBID") && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
int jobID = this.getIntent().getExtras().getInt("JOBID");
if (jobID > 0) {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13220 次 |
| 最近记录: |