Android FCM notification issue

前端 未结 4 741
栀梦
栀梦 2021-01-07 06:50

I am struggling with FCM notifications on Android. The issue is only when the app is closed and not running. I am trying to achieve no click activity I don\'t want the app

4条回答
  •  半阙折子戏
    2021-01-07 07:27

    The notification is getting disappeared when you click on it because you did not add any action when onClick is performed.

    To give onClick functionality on notification, you have to use PendingIntent with the target activity. You can also add additional data into it if needed.

    Before initializing notificationManager, add this code:

    Intent openIntent = new Intent(mContext, TargetActivity.class);
    // Falg to clear the stack. 
    openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
            openIntent, 0);
    notificationBuilder.setContentIntent(pendingIntent);
    

提交回复
热议问题