开发者

Android: How can I include a Notification Sound using a Sound Resource?

开发者 https://www.devze.com 2023-02-24 10:51 出处:网络
Looking at the developer documentation, I see how to use the default sound and how to use a Uri, but I don\'t see how 开发者_如何学Pythonto use a resource. How can I use one of the sounds in my res/ra

Looking at the developer documentation, I see how to use the default sound and how to use a Uri, but I don't see how 开发者_如何学Pythonto use a resource. How can I use one of the sounds in my res/raw folder? Such as an MP3 or WAV file?


Uri path = Uri.parse("android.resource://[package]/[res id]");

Example:

Uri path = Uri.parse("android.resource://com.mypackage/"+R.raw.mysound_1);


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

Add to notification builder

.setSound(soundUri)


You were probably looking for:

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.your_sound);
0

精彩评论

暂无评论...
验证码 换一张
取 消