如何解决应用程序失效期间未收到来自推送通知的数据
我用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 举报,一经查实,本站将立刻删除。