2014-04-12 96 views
0

我有一個完美的通知,但沒有聲音播放,甚至沒有默認的聲音,我嘗試了無數的方法列在本網站上,試圖讓聲音播放,但無濟於事。如何將聲音添加到通知?

如果我創建了媒體播放器,我可以在應用程序啓動時播放音頻文件,但我似乎無法在通知開始時播放該文件。

final Notification.Builder notifyDetailsBuilder = new Notification.Builder(context) 
.setContentTitle("Your Jewellery Received A New Message") 
.setContentText("Click To View Message") 
.setWhen(System.currentTimeMillis()) 
.setSmallIcon(R.drawable.ic_launcher) 
.setAutoCancel(true)     
.setContentIntent(intent); 

final Notification notifyDetails = notifyDetailsBuilder.getNotification();        
mNotificationManager.notify(35178, notifyDetails); 

任何幫助將不勝感激。

回答

0

嘗試

RingtoneManager ringtoneManager = new RingtoneManager(context); 
Uri defaultSoundUri = ringtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
final Notification.Builder builder = new Notification.Builder(context) 
    ... 
    .setSound(defaultSoundUri); 
+0

其餘無論是這兩種方法產生任何聲音。 –

0

設置默認爲0

RingtoneManager ringtoneManager = new RingtoneManager(context); 
Uri defaultSoundUri = ringtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
final Notification.Builder builder = new Notification.Builder(context) 
    .setDefaults(0) 
    .setSound(defaultSoundUri) 

...您的代碼