开发者

Setting Ringtones Inside Android App

开发者 https://www.devze.com 2023-02-08 06:41 出处:网络
I would like the ability to set the systems ringtones from within my Android application.I face a slightly interesting issue because I never once in my code refer to the sounds directly, and instead a

I would like the ability to set the systems ringtones from within my Android application. I face a slightly interesting issue because I never once in my code refer to the sounds directly, and instead am using a setup that refers to them via ints, so the code I have found online for this doesn't quite apply to me.

I'm not sure whether my code to set the ringtone is correct or not. It does replace my ringtone, but it never replaces it with the sound I ask it to. When I was using "Uri.parse" and giving it the path to find the correct file, it would replace the ringtone with nothing. Now, using "Uri.fromFile", and referring to the sound via a File, it replaces it with a typical telephone sound, which I assume is some sort of default.

I don't get any errors from this, but I do get one warning that seems relevant.

dataChanged but no participant pkg='com.android.providers.settings' uid=10096

It seems to me that I am just not referring to the file properly. I can get the path to the sound in a String, and of course define them as a File, but I must be missing something somewhere.

Any ideas are appreciated, thank you.

EDIT :: Well it seems that error only shows up when you "change the ringtone". So if I were to set the same sound as ringtone again, it would not show up, but if I were to set a different sound it would. To me this still means that it is seeing everything I am doing, but I am not referencing to the sound properly, so it doesn't know what to put there.

EDIT :: These are the main points of the errors I get when I try to use the same setup that is posted in other examples of settings ringtones.

These are when I first try to set it as a ringtone :

02-01 11:51:20.709: ERROR/MediaPlayerService(1157): Couldn't open fd for content://settings/system/ringtone

02-01 11:51:20.709: ERROR/MediaPlayer(13807): Unable to to create media player

02-01 11:51:20.709: ERROR/RingtoneManager(13807开发者_StackOverflow): Failed to open ringtone content://settings/system/ringtone

02-01 11:51:20.709: ERROR/MediaPlayer(13807): Unable to to create media player

02-01 11:51:20.716: WARN/Ringtone(13807): Couldn't set the stream type

02-01 11:51:20.716: WARN/Ringtone(13807): java.io.IOException: setDataSourceFD failed.: status=0x80000000

And this is if I go into my volume settings and change the volume of the ringtone :

02-01 11:51:23.568: ERROR/MediaPlayer(13807): Unable to to create media player

02-01 11:51:23.568: ERROR/Ringtone(13807): play() caught 

02-01 11:51:23.568: ERROR/Ringtone(13807): java.io.IOException: setDataSourceFD failed.: status=0x80000000


From your question I am not sure what are you using to change Ringtones. You can use

android.media.RingtoneManager

Several useful links:

How to set ringtone in Android from my activity?

setting audio file as Ringtone

0

精彩评论

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