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()); 

} 

}를 확장

+1

사용자 정의 알림 사용을 설정하려면 다음을 수행하십시오. nb.setDefaults (Notification.DEFAULT_SOUND); 맞춤 알림을 위해 내가 도와 줄 수 없습니다. –

답변

0

알림 빌더에서 사용자 정의 알람 소리를 설정하려면 다음을 수행하십시오의 자원 ID 번호를 사용

int soundResId = R.raw.myCustomSoundResource; 
Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + soundResId); 
nb.setSound(soundUri, AudioManager.STREAM_ALARM); 

res/raw/myCustomSoundResource.ogg과 같은 파일 any of these supported file formats 일 수 있습니다.

관련 문제