【问题标题】:clicking on group of notification is not redirecting to specific screen, instead of that app is restarted in oreo单击通知组不会重定向到特定屏幕,而不是在 oreo 中重新启动该应用程序
【发布时间】:2018-11-22 05:27:24
【问题描述】:

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

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

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

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

Android: Clicking Grouped Notifications Restarts App

How to open non-launcher activity on notification group click

【问题讨论】:

    标签: android android-intent google-cloud-firestore android-notifications android-8.0-oreo


    【解决方案1】:

    您可以使用 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替换为您自己的活动)

    【讨论】:

    • 它不工作,应用程序在点击通知组时重新启动
    • @Pankaj 我需要看看 onMessageReceived 上发生了什么
    • 应用在后台时不会调用onMessageReceived
    【解决方案2】:

    我在 Oreo 中遇到了导致应用程序重启的相同问题,经过多次尝试后我注意到如果在创建通知时我调用 .setGroup(string) 系统不再对通知进行分组。我正在从服务创建通知。这不是我知道的解决方案,但不分组比重新启动应用程序更邪恶。

    【讨论】:

      猜你喜欢
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多