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); 맞춤 알림을 위해 내가 도와 줄 수 없습니다. –