Android: Getting a file Uri from a content Uri?

Just use getContentResolver(). OpenInputStream(uri) to get an InputStream from a URI http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net. Uri ).

Just use getContentResolver(). OpenInputStream(uri) to get an InputStream from a URI. developer.android.com/reference/android/...).

– JMRboosties Apr 14 at 1:22 Check the scheme of the URI returned to you from the chooser activity. If if uri.getScheme. Equals("content"), open it with a content resolver.

If the uri.Scheme. Equals("file"), open it using normal file methods. Either way, you'll end up with an InputStream that you can process using common code.

– Jason LeBrun Apr 14 at 1:37 Great thanks a ton! One more thing... I put the File path of the audio file the user chooses in a SharedPrefs field for the app so the user can preview the selected audio file at any time. When the scheme is file, this works fine.

However with content this has some issues. Is there a way to successfully create a file with a content Uri? – JMRboosties Apr 14 at 1:41 Actually, I just re-read the docs for getContentResolver().openInputStream(), and it works automatically for schemes of "content" or "file", so you don't need to check the scheme... if you can safely assume that it's always going to be content:// or file:// then openInputStream() will always work.

– Jason LeBrun Apr 14 at 1:50 Why do you need to create a file, exactly? You can open audio files via content URIs as well, using the Android MediaPlayer object. – Jason LeBrun Apr 14 at 1:50.

So in my app the user is to select an audio file which the app then handles. The problem I am having is that in order for the app to do what I want it to do with the audio files, I need the Uri to be in file format. The latter is much more accessible for me to work with, but of course I want the app to have functionality with the audio file the user chooses regardless of the program they use to browse their collection.

So my question is, is there a way to convert the content:// style Uri into a file:// Uri? Otherwise, what would you recommend for me to solve this problem? Thank you very much!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions