Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当应用程序初始关闭时,后续(即第一次之后)通知挂起内容不启动活动_Android_Notifications_Broadcastreceiver_Google Cloud Messaging_Android Pendingintent - Fatal编程技术网

Android 当应用程序初始关闭时,后续(即第一次之后)通知挂起内容不启动活动

Android 当应用程序初始关闭时,后续(即第一次之后)通知挂起内容不启动活动,android,notifications,broadcastreceiver,google-cloud-messaging,android-pendingintent,Android,Notifications,Broadcastreceiver,Google Cloud Messaging,Android Pendingintent,场景1-应用程序已打开,在通知中接收PendingEvent,单击通知时 打开包含新内容的活动,每个挂起内容通知 以类似方式在第一次工作后收到 场景2-应用程序已关闭(未运行),在通知中接收PendingEvent,单击通知时 打开包含新内容的活动,每个挂起内容 第一次之后收到的通知在类似情况下不起作用 时尚(不启动活动) 待决意向代码: Intent nIntent=新的Intent(getApplication(),ChatActivity.class) 主要问题: 当用户单击通知(应用

场景1-应用程序已打开,在通知中接收PendingEvent,单击通知时

打开包含新内容的活动,每个挂起内容通知 以类似方式在第一次工作后收到

场景2-应用程序已关闭(未运行),在通知中接收PendingEvent,单击通知时

打开包含新内容的活动,每个挂起内容 第一次之后收到的通知在类似情况下不起作用 时尚(不启动活动)

待决意向代码: Intent nIntent=新的Intent(getApplication(),ChatActivity.class)

主要问题: 当用户单击通知(应用程序已关闭/未运行)时,“活动”将打开并显示新内容(第一次单击),之后的每个通知都不起作用(后续单击)


当应用程序打开,然后通知进来时,一切都正常。

我想你应该拿出
PendingEvent.FLAG_ONE_SHOT
,因为这将使PendingEvent只可用一次。

我添加了一个虚拟动作,如下所示:


例如,nIntent.setAction(“foo”)

我想要相同的结果:当应用程序打开时单击通知,当应用程序关闭时单击通知。
    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());