Android 单击通知后启动程序活动打开(应用程序关闭)

Android 单击通知后启动程序活动打开(应用程序关闭),android,notifications,firebase-cloud-messaging,Android,Notifications,Firebase Cloud Messaging,我正在使用Firebase云消息向我的应用程序发送通知。我有一个名为NoticeActivity的活动,它应该在单击通知栏后打开。如果应用程序是开放的,它工作得很好但如果应用程序已关闭,则在单击通知栏后启动程序活动将打开。 这是通知代码 private static final String TAG = "PUSH NOTIFICATION:"; public int channal_id = 6; //String CHANNEL_ID = "my_channel_01"; @Overr

我正在使用Firebase云消息向我的应用程序发送通知。我有一个名为NoticeActivity的活动,它应该在单击通知栏后打开。如果应用程序是开放的,它工作得很好但如果应用程序已关闭,则在单击通知栏后启动程序活动将打开。 这是通知代码

private static final String TAG = "PUSH NOTIFICATION:";
public  int channal_id = 6; 
//String CHANNEL_ID = "my_channel_01";

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if(remoteMessage.getData().size() > 0){
        Log.d(TAG, " "+ remoteMessage.getData());
    }

    if (remoteMessage.getNotification() != null){
        sendNotifcation(remoteMessage.getNotification().getBody());
    }
}

private void sendNotifcation(String body) {
    Intent intent = new Intent(getApplicationContext(), NoticeActivity.class);
    intent.putExtra("Details", body);
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT );

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("BRAC SK LEARNING")
            .setContentText(body)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
                "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        manager.createNotificationChannel(channel);
    }
    notificationBuilder.setChannelId(CHANNEL_ID);

    manager.notify(001, notificationBuilder.build());
}
当你的应用程序在后台时,Android会发出通知 将邮件发送到系统托盘。用户点击通知打开 默认情况下,应用程序启动器

这包括同时包含通知和数据负载的消息 (以及从通知控制台发送的所有消息)。在这些 在这种情况下,通知会发送到设备的系统托盘,并且 数据有效负载是按照用户的意图额外交付的 发射装置活动

有关向应用程序发送消息的详细信息,请参阅FCM报告 仪表板,记录在iOS上发送和打开的邮件数 和Android设备,以及“印象”(通知)数据 用户可以看到)用于Android应用程序


您认为问题在于FCM实施吗?当您的启动活动从通知开始时,它将包含您需要的所有信息作为“附加信息”。然后,您可以决定在应用程序中导航到何处。是否无法从通知中直接打开NoticeActivity(而不打开任何其他活动)?AFAIK当应用程序被终止时,答案是否。