Skopiowałem plik mp3 (kalimba.mp3) do folderu raw
w folderze res
. Ale kiedy powiadomienie zostanie uruchomione, generuje domyślny dźwięk.Jak ustawić powiadomienie z dźwiękiem niestandardowym w Androidzie
ten sposób robię powiadomienia:
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);
}
Twój kod wygląda ok. Spróbuj ponownie uruchomić emulator lub telefon. http://stackoverflow.com/questions/5682321/android-notification-sound-defaulting-back-instead-of-playing-custom-sound –