要解决Android Firebase通知没有声音的问题,可以尝试以下解决方法:
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri);
Uri customSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.custom_sound);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(customSoundUri);
在这个示例中,您需要将自定义声音文件命名为"custom_sound"并将其放置在res/raw文件夹中。
请注意,这些解决方法中的代码示例基于使用Firebase Cloud Messaging(FCM)实现通知。确保在您的项目中正确集成了FCM库,并正确处理接收到的消息。