应用程序失效期间未收到来自推送通知的数据

问题描述

我用firebase的Cloud消息编写了一些代码。代码运行正常(我在前台和后台都收到了通知),但是我想解决的问题是,每当应用程序死机/被杀死时,当我从后台通知中打开活动时,通知中的内容没有检索。我做了很多研究,尝试了与文章和代码不同的方法。但是这个问题仍然存在。我该怎么办?预先感谢

public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    notiicationTitle = Objects.requireNonNull(remoteMessage.getNotification()).getBody();
    notiicationBody = remoteMessage.getNotification().getTitle();

    showNotification(AppConstants.NOTIFICATION_CHANNEL,notiicationBody,notiicationTitle);
}


private void showNotification(String channel,String name,String description) {
    mChannel = new NotificationChannel(channel,name,AppConstants.FCS_NOTI_IMPO);
    mChannel.setDescription(description);
    mChannel.setShowBadge(true);

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

    assert notificationManager != null;
    notificationManager.createNotificationChannel(mChannel);

    mapActivity = new Intent(this,ActivityMaps.class);
    mapActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mapActivity.putExtra(AppConstants.NOTIFICATION_TITLE,notiicationTitle);
    mapActivity.putExtra(AppConstants.NOTIFICATION_BODY,notiicationBody);

    broadcaster.sendBroadcast(mapActivity);

    contentIntent = PendingIntent.getActivity(this,mapActivity,PendingIntent.FLAG_CANCEL_CURRENT);
    notification = new Notification.Builder(getApplicationContext())
      .setContentTitle(name)
      .setContentText(description)
      .setSmallIcon(R.drawable.logistics)
      .setChannelId(channel)
      .setOngoing(true)
      .setContentIntent(contentIntent)
      .build();

    notificationManager.notify(AppConstants.NOTIFICATION_ID,notification);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...