How to set sound for notification?

2019-09-06 16:30发布

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");

2条回答
We Are One
2楼-- · 2019-09-06 16:51

try the following:

   notifyDetails.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
查看更多
等我变得足够好
3楼-- · 2019-09-06 17:00

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);
查看更多
登录 后发表回答