0

GCM을 통해 Android 휴대 전화에 알림을 보내면 앱이 실행 중일 때 또는 사용자가 알림을 클릭 할 때 재생되는 사운드 이름을 보냅니다.앱을 닫을 때 푸시 알림 소리를 변경할 수 있습니까?

내 질문에 알림의 소리를 바꿀 수 있습니까? 사용자가 알림을 클릭 할 때가 아니라 전화에서 알림이 팝업 될 때. 나는 그것이 가능하다는 것을 알고있다. Yo app은 "YO"라는 알림 소리가 나올 때 소리를 낸다.

내 영어로 죄송합니다. 도움을 주셔서 감사합니다.

답변

0

알림을 작성할 때 setSound(uri)을 사용하여 소리에 알림을 설정할 수 있습니다.

public NotificationCompat.Builder setSound (Uri sound) 

Set the sound to play. It will play on the default stream. 

또는 setDefaults(Notification.DEFAULT_SOUND)을 기본 사운드 재생에 사용할 수 있습니다. 예를 들어

:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) 
    .setDefaults(Notification.DEFAULT_SOUND) 
    .setTicker (text) 
    .setSmallIcon(R.drawable.icon) 
    .setContentText (text) 
    .setContentTitle(title) 
    .setStyle(new NotificationCompat.BigTextStyle().bigText(text)) 
    .setAutoCancel(true).setNumber (4) 
    .setContentIntent(contentIntent); 

mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 

지금까지 내가 아는 한, 통지가 표시 될 때 (내가 확인하지 않은 있지만)이 사운드가 재생됩니다. 그러나 그렇지 않은 경우 mNotificationManager.notify에 전화하기 전에 알림 (방송 수신기 또는 의도 서비스에서)을 나타내는 코드의 알림과 상관없이 사운드를 재생할 수 있습니다.

관련 문제