随后(即第一次之后)通知未决意图在应用程序初始关闭时未启动 activity
Subsequent(ie. AFTER FIrst) notification pendingintent not launching activity when app is initailly closed
场景 1 - 应用已打开,在通知中收到 pendingintent,当通知被点击时,
opens activity with new content, every pendingintent notification
received after the first works in a similar fashion
.
场景 2 - 应用已关闭(不是 运行),在通知中收到 pendingintent,当通知被点击时,
opens activity with new content, every pendingintent
notification received after the first does not work in a similar
fashion (doesn't launch activity)
.
待定意向代码:
Intent nIntent = new Intent(getApplication(), ChatActivity.class);
nIntent.putExtra("chattingFrom", chattingToName);
nIntent.putExtra("chattingToName", chattingFrom);
nIntent.putExtra("chattingToDeviceID", chattingFromDeviceID);
nIntent.putExtra("chattingFromDeviceID", chattingToDeviceID);
NOTIFICATION_ID = NOTIFICATION_ID + 1;
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, nIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Chat App")
.setStyle(new NotificationCompat.BigTextStyle().bigText("New message from " + chattingFrom + ": " + msg))
.setContentText("New message from " + chattingFrom + ": " + msg)
.setAutoCancel(true)
.setTicker("New message from " + chattingFrom)
.setSound(sound);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
主要问题:
当用户点击通知时(应用程序是 closed/not 运行),activity 打开新内容(第一次点击),之后的每个通知都不起作用(后续点击)。
应用程序打开时一切正常,然后收到通知。
我认为您应该删除 PendingIntent.FLAG_ONE_SHOT
,因为这会使 PendingIntent 只能使用一次。
我在我的意图中添加了一个虚拟操作,见下文:
例如nIntent.setAction("foo")
场景 1 - 应用已打开,在通知中收到 pendingintent,当通知被点击时,
opens activity with new content, every pendingintent notification received after the first works in a similar fashion
.
场景 2 - 应用已关闭(不是 运行),在通知中收到 pendingintent,当通知被点击时,
opens activity with new content, every pendingintent notification received after the first does not work in a similar fashion (doesn't launch activity)
.
待定意向代码: Intent nIntent = new Intent(getApplication(), ChatActivity.class);
nIntent.putExtra("chattingFrom", chattingToName);
nIntent.putExtra("chattingToName", chattingFrom);
nIntent.putExtra("chattingToDeviceID", chattingFromDeviceID);
nIntent.putExtra("chattingFromDeviceID", chattingToDeviceID);
NOTIFICATION_ID = NOTIFICATION_ID + 1;
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, nIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Chat App")
.setStyle(new NotificationCompat.BigTextStyle().bigText("New message from " + chattingFrom + ": " + msg))
.setContentText("New message from " + chattingFrom + ": " + msg)
.setAutoCancel(true)
.setTicker("New message from " + chattingFrom)
.setSound(sound);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
主要问题: 当用户点击通知时(应用程序是 closed/not 运行),activity 打开新内容(第一次点击),之后的每个通知都不起作用(后续点击)。
应用程序打开时一切正常,然后收到通知。
我认为您应该删除 PendingIntent.FLAG_ONE_SHOT
,因为这会使 PendingIntent 只能使用一次。
我在我的意图中添加了一个虚拟操作,见下文:
例如nIntent.setAction("foo")