0

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): 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
Raphy
  • 5
  • 1
  • 3

1 Answers1

0

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

Community
  • 1
  • 1
Zelimir
  • 11,008
  • 6
  • 50
  • 45
  • I've edited my main post with the bullet points of my error log when I try to use the code from those examples. Admittedly I just kind of slapped the code in and changed what I needed to, but earlier I did take quite a bit of time trying to get it working with that code and it gave me similar, if not the same, results. Thank you for the links either way, I will continue studying them to see if I can't get things going. – Raphy Feb 01 '11 at 18:02
  • From your log I can see that you are using URI where file path should come. If you do not manage to solve it, I can help you tommorow. Regards. – Zelimir Feb 01 '11 at 18:32
  • I've experimented for a while trying different things based on what you said, but it still wouldn't set the ringtone properly. I'm sure it's something very simple, my major issues almost always are. Thank you for taking the time to help. – Raphy Feb 02 '11 at 02:14
  • So, currently you have file path to some sound and want to set it as ringtone? Is that new sound or already persists on the phone for some time? – Zelimir Feb 02 '11 at 06:57
  • It is actually simply a sound within my app, in the res/raw directory. I wasn't sure if I needed to physically save it out to some other storage in order to set it as a ringtone, or if it would save that sound somewhere specific automatically when I did. It's kind of complicated how it works currently, but I go through a few different methods to be able to get either the path to that sound or assign it to a File to be used. I didn't read anything that said I specifically needed to save the sound to some storage to use it as a ringtone, but that would make sense now that I think about it. – Raphy Feb 02 '11 at 17:14
  • Yes, I am asking because RingtoneManager function for setting default ringtone setActualDefaultRingtoneUri() expects Media.Audio Uri to be selected. In order to be able to do that, ringtone should be placed in some Sound dir on SD card. – Zelimir Feb 02 '11 at 17:50
  • I see. That would make more sense I suppose. So the setup I use is likely correct, but I was trying to refer to a sound within my app and it couldn't be found instead of looking for a saved sound somewhere in storage. I've never saved a file out before, but I should be able to figure it out without bothering you further. Thank you very much for your help. – Raphy Feb 02 '11 at 18:22