How to convert absolute path to URI in android java

  • Replies:2
  • OpenNot stickiedUnanswered
  • 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
  • Forum posts: 5

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