15

Question: I have found that java.net.URI has a create(String uri) option but the android.net.uri does not.

More specifically: I am trying to grab the output of RingtoneManager's RingtonePicker and set it as the default ringtone with SetActualDefaultRingtoneUri:

Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE
                     ,RingtoneManager.TYPE_RINGTONE);

intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TITLE
                     , "Select Tone For Rainy Days");

startActivityForResult(intent, 0);

RingtoneManager.setActualDefaultRingtoneUri(this
                     ,RingtoneManager.TYPE_RINGTONE
                     ,RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

The problem is that RingtoneManager.EXTRA_RINGTONE_PICKED_URI returns a string not a URI. There might be a better way than to convert the string to a URI. I cannot find a reason why java.net.URI can do it and android.net.Uri can't.

Any suggestions would be appreciated!

bunbun
  • 2,595
  • 3
  • 34
  • 52
FeelTheBurns
  • 1,065
  • 2
  • 8
  • 14
  • 1
    See this if it helps you http://stackoverflow.com/questions/3487389/java-convert-string-to-uri/3487413#3487413 – ccheneson Oct 07 '10 at 19:30

2 Answers2

36

I guess you want to use the parse method from the android.net.uri class. It returns a URi for the supplied encoded string.

android.net.uri parse()

methode
  • 5,348
  • 2
  • 31
  • 42
0

Thanks guys, but this is how I ended up making it work

Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_RINGTONE,uri);
CoolBeans
  • 20,654
  • 10
  • 86
  • 101
FeelTheBurns
  • 1,065
  • 2
  • 8
  • 14