android版本8+;中未收到FCM通知;另外,未调用onMessageReceived()
这是我的代码android版本8+;中未收到FCM通知;另外,未调用onMessageReceived(),android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,这是我的代码 有人能帮我吗 firebase依赖项:实现“com.google.firebase:firebase消息传递:12.0.1” buidgradle main:classpath'com.google.gms:google服务:4.0.1' 我已经试过了你是如何发送消息的?这是fcm令牌的问题,只是因为更新了firebase依赖性。 @Override public void onMessageReceived(RemoteMessage remoteMessage) {
有人能帮我吗
firebase依赖项:实现“com.google.firebase:firebase消息传递:12.0.1”
buidgradle main:classpath'com.google.gms:google服务:4.0.1'
我已经试过了你是如何发送消息的?这是fcm令牌的问题,只是因为更新了firebase依赖性。
@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());
}