Ah, sorry about the docs not mentioning the part about the URI needing to be pointing to the Media provider.
FWIW, you shouldn't need to touch the Settings provider directly, the call to setActualDefaultRingtoneUri will do that for you. jason On Thu, May 21, 2009 at 12:26 AM, [email protected] <[email protected]> wrote: > > Oye...After 8 hours of debugging, I finally figured it out. I thought > I would share in case someone else ran into the problem later on. > > To programmatically change a ringtone WITHOUT using a ringtone picker, > you will need to write the ringtone data into the system settings. > > Like this ----> Settings.System.putString(context.getContentResolver > (), Settings.System.RINGTONE, ringtoneUri.toString()); ( Settings -> > android.provider.Settings) > > The only catch is that you need to use the MediaStore > (android.provider.MediaStore) and it's URI's to the external memory to > actually get the ringtones you want. > > The real tricky part is figuring out what id represents what > ringtone. > > If you don't know, the MediaStore lays out everything in your external > storage(namely "sdcard") into a simple table. Each item inside the > MediaStore can be referenced by their numerical id's, 1 - # of files, > which basically means referencing anything on the sdcard is impossible > unless you know it's id #. How do you figure out the id #? Well, i'll > leave that up to the reader to figure out(I'm sure there is more then > one way to do it). But keep in mind that if you are looking for > something in the MediaStore, you will need a Cursor > (android.database.Cursor) to iterate through its rows and columns. > > Though it took me all day to weed out the results, the code is > actually only a couple of lines. It will get all the id's for a list > of ringtones that I grabbed from a directory earlier on and then makes > it referenceable by using the file name(*hint* hashtable). Anyway, if > anyone has questions on anything this specifically, just email me, > [email protected] > > Cheers > > On May 19, 11:00 pm, "[email protected]" <[email protected]> wrote: >> I was wondering if anyone knows how to set a ringtone from off the >> sdcard correctly cause obviously I'm doing it wrong. >> >> For some reason, I'll set the ringtone(it's actually picked randomly) >> as the default ringtone using the >> RingtoneManager.setActualDefaultRingtoneUri() method. This works, and >> it show's that ringtone as the default ringtone in the settings menu >> (as well as plays the correct tone), but when I get called it plays a >> system ring instead of that default ringtone I set. >> >> Has anyone else ran into this problem?? I've been looking everywhere >> online with no luck. I actually have a feeling it has something with >> the formatting of the Uri but I'm not sure on how else to format it. >> >> My current format: >> Uri ringtoneUri = Uri.fromFile(new File(directory +"/" + >> ringtones.get >> (whatTone))); >> >> directory = "/sdcard/media/ringtones" --- Just an example, this is >> actually user generated >> ringtones.get(whatTone) = "BlindedInChains.mp3" --- Also just an >> example >> >> End result of this format: >> "file:///sdcard/media/ringtones/BlindedInChains.mp3" >> >> Is this wrong?? Help Please!! :) >> Thanks in advance! > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

