java - 推送通知未在通知栏 Android 中显示
问题描述
解决方案
You can try using this channel thing introduced in OREO. May be that is causing the issue.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public static final String TAG = "FirebaseSerive";
public static final String NOTIFICATION_CHANNEL_ID = "IMP_NOTIFICATIONS";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
Notification.Builder notification = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ss_icon);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
assert mNotificationManager != null;
notification.setChannelId(NOTIFICATION_CHANNEL_ID);
mNotificationManager.createNotificationChannel(notificationChannel);
}
mNotificationManager.notify(/*notification id*/0, notification.build());
}
}
Edit: may be you are getting notification payload instead of data, which you can check by using below code.
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
推荐阅读
- image - Julia - 如何使用函数“imshow”调整图像大小?
- reactjs - React 最终形式 - 字段数组 - 原始形式
- sql - 从多对多关系表中过滤项目
- deno - Deno 将表达式/脚本评估到内存中
- java - 在 graal 上下文中添加到静态类 Math 的绑定
- javascript - 无法在 node.js 上接收正文数据
- python - 在 Python 中操作包含其他列表的列表
- c# - 我可以在 C# 中模板化 Func 吗?
- javascript - Prev/Next 循环遍历 li 类处于活动状态的列表
- python - 使用 pytube 和 tkinter 在画布中显示 youtube 视频的缩略图