How to convert absolute path to URI in android java

  • Replies:3
Mahnoor Fatima
  • Forum posts: 1

Oct 7, 2017, 1:12:03 PM via Website

Hi folks,

I wanted to convert a path like : /sdcard/DCIM/Camera/VID

to: content://media/external/video/media/34347

I have tried: Uri.Parse(content://media/external/video/media/34347
) but still it have the same path of /sdcard/DCIM/Camera/VID

Can someone tell me how to convert this filepath to URI?

Thanks

Reply
Sivanagamahesh Gorijala
  • Forum posts: 2

Nov 10, 2017, 6:17:33 AM via Website

Please try the following code

Uri.fromFile(new File("/sdcard/sample.jpg"))

Reply
zmirli nazim
  • Forum posts: 7

May 21, 2018, 5:56:53 AM via Website

Below code works fine before 18 API :- public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }

Reply
Dmnjeet Singh
  • Forum posts: 1

Aug 27, 2022, 4:43:26 AM via Website

can you help me please tell how to connect you

Reply