android implements Uri's method of getting the real path to File

  • 2020-06-19 11:43:53
  • OfStack

This article illustrates how android implements Uri to convert real paths to File. Share to everybody for everybody reference. Specific implementation methods are as follows:


Uri uri = data.getData();
String[] proj = { MediaStore.Images.Media.DATA };
Cursor actualimagecursor = managedQuery(uri,proj,null,null,null);
int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToFirst();
String img_path = actualimagecursor.getString(actual_image_column_index);
File file = new File(img_path);

Hopefully, this article has been helpful in your Android programming.


Related articles: