首页 文章

当应用程序初始关闭时,后续(即AFTER FIrst)通知pendingintent不启动活动

提问于
浏览
1

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

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

.

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

打开包含新内容的活动,在第一次收到后,收到的每个待审通知都以类似的方式工作(不启动活动)

.

待定意图代码:意图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());

Main Problem: 当用户点击通知(应用已关闭/未运行)时,将打开包含新内容(第一次点击)的活动,之后的每个通知都不起作用(后续点击) .

当应用程序打开时,一切正常,然后通知进入 .

2 回答

  • 1

    我认为你应该拿出 PendingIntent.FLAG_ONE_SHOT ,因为这会使PendingIntent只能使用一次 .

  • 0

    我为我的意图添加了一个虚拟动作,见下文:

    例如nIntent.setAction(“foo”)

相关问题