【发布时间】:2023-03-13 23:50:02
【问题描述】:
我在应用运行时收到 Firebase 通知声音,而在应用处于后台时没有收到通知声音。我不知道为什么会这样。
这是我尝试过的
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_MAX);
// To Configure the notification channel.
notificationChannel.setDescription("Sample Channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.BLUE);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.gj512x512)
.setContentText(message)
.setSound(sound)
.setContentTitle(title)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
notificationManager.notify(1, noBuilder.build());
}
请帮帮我。
【问题讨论】:
-
您的意思是当您收到 FCM 通知时对吗?
-
是的,这是一个 fcm 通知
标签: android firebase notifications firebase-cloud-messaging