0

andand 어플리케이션과 함께 Firebase 메시징을 사용하고 있습니다. Firebase를 사용하여 푸시 알림을 보내고 있습니다. 기본 알림 사운드를 맞춤 알림 사운드로 변경하고 싶습니다. 내가 어떻게 해 ? 위의 코드FCM 맞춤 알림 소리

Uri defaultSoundUri = 
    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setLargeIcon(image)/*Notification icon image*/ 
      .setSmallIcon(R.mipmap.ic_notif) 
      .setContentTitle(title) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent) 
      .setCustomBigContentView(remoteViews) 
      .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image)) 
      ; 


    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(Integer.parseInt(id) /* ID of notification */, notificationBuilder.build()); 
} 
+1

[this] (https://www.myflashlabs.com/custom-icon-sound-fcm-air-native-extension/) 문서는 매우 유용합니다. 사용자 정의 사운드를 처리하는 방법을 설명합니다. –

답변

1
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.pop); 
notification.defaults |= Notification.DEFAULT_VIBRATE; 

사용은 자원에서 사용자 정의 사운드를 추가 할 수 있습니다.

알림 클래스를 사용하는 경우 위 코드를 사용할 수 있습니다.

Notification notification = new Notification(icon, tickerText, when); 

NotificationBuilder를 사용하면서 아래 코드를 사용하십시오.

Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd); 
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
     .setLargeIcon(image)/*Notification icon image*/ 
     .setSmallIcon(R.mipmap.ic_notif) 
     .setContentTitle(title) 
     .setAutoCancel(true) 
     .setSound(sound) 
     .setContentIntent(pendingIntent) 
     .setCustomBigContentView(remoteViews) 
     .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image)) 
     ; 
+0

어디서 교체해야합니까? 코드를 위의 코드로 수정할 수 있습니까? –

+0

편집 된 답변을 확인하십시오. –

+0

그것 [일했다] 아주 많이 동생 고마워요 :) 그것은 나를 많이 도왔습니다 :) –

0

사용 setSound() 방법 소리

if(!silent) { // check if phone is not in silent mode 
     notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); 
     NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(9999, notificationBuilder.build()); 
    } 
} 

을 설정 또는 장치의 기본 사운드를 사용하려는 경우

{ 
    "to" : "XXYYXXYY...", 

    "notification" : { 
     "body" : "The stock opened on a bullish note at Rs. 449 and touched a high of Rs. 461.35, up 5.06 per cent over its previous closing price on the BSE. A similar movement was seen on the NSE where the stock opened at Rs. 450 and hit a high of Rs. 463.70, up 5.32 per cent.", 
     "title" : "Stocks in focus: Kalpataru Power, Punj Lloyd, J B Chem, Bharti Airtel", 
     "icon" : "ic_stock", 
     "sound" : "res_notif_sound" 
    } 
} 

을 사용할 수 있습니다, 당신은 사용해야합니다 를 "소리": "기본".

+0

현재 코드로 사용자 정의 할 수 없습니까? –

+0

@ 잭 아니, 귀하의 의견을 이해할 수 없습니다. – Rinav