android - 在 android 版本 8+ 中未收到 FCM 通知,也未调用 onMessageReceived()
问题描述
这是我的代码
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, SOMEACTIVITY.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL);
notificationBuilder.setSmallIcon(R.drawable.ic_notification_white_icon);
if (image != null) {
notificationBuilder
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(image).setSummaryText(messageBody));/*Notification with Image*/
} else {
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody));
}
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel Name",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0, notificationBuilder.build());
}
任何人都可以帮助我对
firebase的依赖:实现'com.google.firebase:firebase-messaging:12.0.1'
buidgradle main : 类路径 'com.google.gms:google-services:4.0.1'
我已经尝试过FCM 通知没有在 Oreo 的后台被调用
解决方案
推荐阅读
- mysql - 通过另一列的数据更新一列的特定部分
- angular - 一旦用户点击编辑铅笔图标,它应该打开一个新的模式对话框
- post - 在 snaplogic 上的 REST POST 快照上将文件发送到 api 端点时,如何修复错误 400“找不到文件”?
- javascript - 如果我去'/contact',我想保留以前的路线视图但显示一个模式
- dependency-management - npm eslint-config 包是否应该将它扩展的配置包放在 devDependencies 中?
- python - 在熊猫中连续获取计数唯一值
- jquery - 如何在jQuery中做一个简单的图像爆炸
- function - React Native 运行任何外部屏幕的功能
- javascript - 使用角度 2 以印度格式显示数字
- javascript - 如何创建 JavaScript 库?