当应用被用户或后台应用终止时,活动无法启动并点击FCM推送通知

时间:2018-12-21 09:38:04

标签: android firebase android-intent push-notification background

我正在设置FCM推送通知,并且当我杀死应用程序或后台应用程序并生成通知时,然后单击通知然后应用程序无法打开时也会生成通知。

>

通过其余api到Firebase后端的发布请求生成通知。

我也通过FCM Notification Quick Project检查了同样的问题。

注意:->默认情况下,用户点击通知会打开应用启动器。在默认活动打开后,此操作将不起作用,然后我将从系统任务栏中获取数据。

https://github.com/firebase/quickstart-android/issues/765

https://firebase.google.com/docs/cloud-messaging/android/receive#backgrounded

1 个答案:

答案 0 :(得分:0)

private NotificationManager mNotificationManager;
        private static int NOTIFICATION_ID = 0; 

private void sendNotification(String msg) {

        PendingIntent contentIntent = null;
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setContentTitle("Title")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

        mBuilder.setContentIntent(contentIntent);
        mBuilder.setAutoCancel(true);

        Random random = new Random();
        NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000;
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }