我複製了MP3(kalimba.mp3)文件輸出到在res
文件夾中的文件夾raw
。但是當通知被觸發時,它會產生默認聲音。如何設置自定義聲音通知在Android的
這是如何使一個通知:
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);
}
您的代碼看起來確定。嘗試重新啓動你的模擬器或手機。 http://stackoverflow.com/questions/5682321/android-notification-sound-defaulting-back-instead-of-playing-custom-sound –