这是我的代码
@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 Notifications not getting called in background for Oreo