本文介绍了Android Firebase通知未出现在android 8或更高版本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该通知在android 8或更高版本中不显示,但在android 8或更低版本中正常显示
the notification doesn't show in android 8 or higher, but its works fine in android 8 lower
这是我的尝试
String code,code1,code2,title,message,image,urlImage;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
kode = remoteMessage.getData().get("code");
kode1 = remoteMessage.getData().get("code1");
kode2 = remoteMessage.getData().get("code2");
title = remoteMessage.getData().get("title");
message = remoteMessage.getData().get("message");
image = remoteMessage.getData().get("image");
urlImage = remoteMessage.getData().get("image");
sendNotification_1(title,message, bitmap, code);
}
private void sendNotification_1(String title,String messageBody, Bitmap image, String kode){
Intent intent = new Intent(this, Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("directto", kode);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(image != null){
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(convertToBitmap())/*Notification icon image*/
.setSmallIcon(R.drawable.logostar)
.setContentTitle(title)
.setContentText(messageBody)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(image))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */,
notificationBuilder.build());
}
}
那是我的代码之上,但在更高版本的android 8中仍然无法使用
Thats above my code , it still doesn't work in android 8 higher
像大家一样建议我编辑的代码但还是不行
bellow my edited code like you all suggestedbut still doesn't work
推荐答案
从android8开始,需要与所有通知关联的渠道.
From android8 onward, need a channel associate with all notification.
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;
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
mNotificationManager.createNotificationChannel(notificationChannel);
}
这篇关于Android Firebase通知未出现在android 8或更高版本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!