In an Activity, I can choose an image from the Gallery, and I need its Uri path (in the log, the Uri path for my test image is /content:/media/external/images/media/1
).
I'm getting this error though:
08-04 02:14:21.912: DEBUG/PHOTOUPLOADER(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory) 08-04 02:14:32.124: WARN/System.err(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
Is this the correct format of a file path? Or should I make it to be something like sdcard\...\image.png
?
"gallery" is an app, not a location. Your pictures on your phone could be located anywhere, depending on how they got on your phone. Your camera will store its images at "/DCIM/camera", or a similar location. Social media apps may download photos into the "/download" folder or a folder under the app's name.
URI or Uniform Resource Identifier is a compact sequence of characters that identifies an abstract or physical resource. It can be further classified as a locator, a name, or both. Basically URI (in some cases URL or URN) will point to the image location, or will be the name of the image (why not both?).
Uri uri = data. getData(); File file = new File(uri. getPath());//create path from uri final String[] split = file. getPath().
public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
val inputStream = context.contentResolver.openInputStream(uri)
is all you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With