简体   繁体   中英

How to define a sound in my project as ringtone and notification?

I have done an apk that play sounds (*.ogg) and now I need to know how to set then as ringtone and notification, I already done a menu and buttons where I can obtain the name of the sound to define, they are inside de apk project in res/raw folder... I have no ideia of how to do that...

Thanks guys =)

If you have a sound file in res/raw , you can get the Uri for it like this:

Uri ringtone = Uri.parse("android.resource://{package}/{resource_id}");

Then, with the Uri , you can play the ringtone like this:

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(ringtone.getPath());
mp.prepare();
mp.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM