1
我發佈了用於檢索郵件並顯示來自Firebase的通知的代碼。我收到正確的文本和標題的通知,但此通知是無聲的。即使我設置了默認聲音或自定義聲音。 如何播放正確的聲音?Android通知生成器不播放自定義聲音
公共類NotificationMessagingService擴展FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d("sb.fbv", "NotificationMessaginService.onmessageReceived");
String title = remoteMessage.getNotification().getTitle();
String subText = remoteMessage.getNotification().getBody();
String message = remoteMessage.getData().get("subtext");
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
nb.setContentTitle(title);
nb.setSubText(message);
nb.setContentText(subText);
nb.setSmallIcon(R.drawable.notificavedelago);
nb.setAutoCancel(true);
nb.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
nb.setLights(Color.BLUE, 3000, 3000);
//SOUND DEFAULT
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
nb.setSound(alarmSound);
//CUSTOM SOUND
//Uri customSound= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound);
//nb.setSound(customSound);
nb.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, nb.build());
}
}
要設置自定義通知使用: nb.setDefaults(Notification.DEFAULT_SOUND); 對於自定義通知,我無法幫助您 –