Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a String to an android.net.Uri

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!

like image 884
FeelTheBurns Avatar asked Oct 07 '10 19:10

FeelTheBurns


People also ask

How do I change my URL to URI?

The getURI() function of URL class converts the URL object to a URI object. Any URL which compiles with RFC 2396 can be converted to URI. URLs which are not in the specified format will generate an error if converted to URI format. Parameter: This method do not accept any parameter.

What is an android URI?

A URI is a uniform resource identifier while a URL is a uniform resource locator.


1 Answers

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()

like image 104
methode Avatar answered Nov 05 '22 22:11

methode