如何为通知设置自定义声音

时间:2017-11-01 18:34:03

标签: java android firebase

我知道这个问题之前已经得到了回答,但仍然无法使其成功。我已经将mp3放入原始文件夹,我知道它的路由是有效的,因为我测试了Ringtone和MediaPlayer类。通知创建正常,但没有声音(我的设备上的音量最大)。这是我的代码

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)   
.setLargeIcon(icon)   
.setSmallIcon(R.drawable.logo)  
.setContentTitle(notification.getTitle())   
.setContentText(notification.getBody())   
.setSound(sound)   
.setPriority(Notification.PRIORITY_HIGH);     
mBuilder.setContentIntent(contentIntent);   
Notification mNotification = mBuilder.build();   
mNotification.sound = sound;   
NotificationManager mNotificationManager = (NotificationManager) context    
.getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mNotification);

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT data
FROM Table1               
LEFT JOIN table2 
  (on Table1.column1 = Table2.column1)
WHERE @Table1.ColumnName = 'Table1.column1'  

UNION ALL

SELECT data
FROM Table1               
LEFT JOIN Table2 
  (on Table1.column2 = Table2.column1)
WHERE @Table1.ColumnName = 'Table1.column2' 

<强>(或)

 notification.sound =Uri.parse("android.resource://"+context.getPackageName()+"/"+R.raw.FILE_NAME);//Here is FILE_NAME is the name of file that you want to play