我的问题是,如果我在华为设备上运行我的应用程序,我不会收到任何通知,但是,如果我在另一台设备上运行我的应用程序,它可以正常工作,并且您在FirebaseMessagingService
的通知代码下方找到:
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
Random generator = new Random();
String id = data.get("element");
String type = data.get("type");
Intent intent;
intent = new Intent(this, Home.class);
intent.putExtra("retour", type + "test");
intent.putExtra("element_id", id);
intent.setAction(Long.toString(System.currentTimeMillis()));
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);//RingtoneManager.TYPE_NOTIFICATION
long[] pattern = {500, 500, 500, 500, 500, 500, 500, 500, 500};
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this);
notificationbuilder.setContentTitle(notification.getTitle());
notificationbuilder.setContentText(notification.getBody());
notificationbuilder.setAutoCancel(true);
notificationbuilder.setVibrate(pattern);
notificationbuilder.setSound(defaultSoundUri);
notificationbuilder.setSmallIcon(R.drawable.icoapp_and);
notificationbuilder.setColor(getResources().getColor(R.color.colorAccent));
notificationbuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(generator.nextInt(), notificationbuilder.build()); }
答案 0 :(得分:0)
尝试以下代码将频道添加到NotificationManager
:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(idChannel,
context.getString(R.string.app_name), importance);
// Configure the notification channel.
mChannel.setDescription(context.getString(R.string.alarm_notification));
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400,
300, 200, 400});
mNotificationManager.createNotificationChannel(mChannel);
} else {
builder.setContentTitle(context.getString(R.string.app_name))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setColor(ContextCompat.getColor(context, R.color.transparent))
.setVibrate(new long[]{100, 250})
.setLights(Color.YELLOW, 500, 5000)
.setAutoCancel(true);
}