我将 mp3 (kalimba.mp3) 文件复制到 res
文件夹中的 raw
文件夹中。但是当通知被触发时,它会产生默认的声音。
这是我发出通知的方式:
protected void GenerateNotify() {
NotificationManager myNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(android.R.drawable.ic_btn_speak_now,"hi",100);
Intent intent=new Intent(getApplicationContext(),as.class);
PendingIntent contentintent=PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
notification.setLatestEventInfo(getApplicationContext(), "Hi","date", contentintent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = Uri.parse("android.resource://com.example.serviceproject/" + R.raw.kalimba);
myNotificationManager.notify(NOTIFICATION_ID,notification);
}
最佳答案
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
if defined DEFAULT_SOUND, then the default sound overrides any sound
关于android - 如何在android中使用自定义声音设置通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13760168/