How to set sound for notification?

邮差的信 提交于 2019-12-11 14:38:19

问题


I copied the .mp3 file in assets. When notification raises, file is not playing

Could anyone please help me.

notification.sound = Uri.parse("file:///android_assets/alarm_951.mp3");

回答1:


try the following:

   notifyDetails.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;



回答2:


Instead of copying your file to the assets folder copy it to resources/raw/ and then use

Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.mysound);
mBuilder.setSound(sound);


来源:https://stackoverflow.com/questions/13099700/how-to-set-sound-for-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!