How to extract real file URI or file data from a path that looks like "/ content: / media / external / video / media / 19"?

I am desperate to send the captured video to the server. The problem is that the URI that is set by the camera’s embedded application is not a real file path. It looks like this: /content:/media/external/video/media/19 .

How can I access the real path or data directly from this type of URI?

After reading the Android documentation, I saw that it looked like a content provider notation, but I still don't know how to find the data I need. Please, help!!!

early

+4
source share
2 answers

How can I access the real path or data directly from this type of URI?

Not. It may not exist as a file. Or it may not exist as a file that you can read, except through ContentProvider .

Instead, use a ContentResolver to open an InputStream on this Uri , and use an InputStream to send data to the server.

+3
source
 public String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try { String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } } 

see the next post for Get the file name and path from the URI from the media bar

+1
source

Source: https://habr.com/ru/post/1399405/


All Articles