首页 > 解决方案 > 单击通知组不会重定向到特定屏幕,而不是在 oreo 中重新启动该应用程序

问题描述

我已经在我的聊天应用程序中实现了 firebasse 通知功能,一切都运行良好,但现在在 Android os 8.0 和 8.1 中进行测试时,当应用程序在后台时,如果用户收到 4 个或超过 4 个通知,那么它会组合成组并当用户单击时在组上然后没有得到意图并且应用程序重新启动。

如果用户点击单个通知,那么我可以在特定屏幕中发送他。

我想要通知数据或聊天 ID,以便我可以在特定屏幕中发送他,但不会获得任何意图数据。

我在stackoverflow中搜索了类似的问题,但仍然没有得到正确的结果。

Android:单击分组通知重新启动应用程序

如何在通知组单击时打开非启动器活动

标签: androidandroid-intentgoogle-cloud-firestoreandroid-notificationsandroid-8.0-oreo

解决方案


您可以使用 setContentIntent 设置 Intent 的值,如下所示

    Intent intent = new Intent(this, SecondActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.your_notification_icon)
                    .setContentTitle("Notification Title")
                    .setContentText("Notification ")
                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, mBuilder.build());

它将打开 SecondActivity(将 SecondActivity 替换为您自己的活动)


推荐阅读