0

I have image uri like this :"content://com.iceburgapp.provider/external_files/.pkgName/File1.jpg"

Now whenever I get path it give me : "/external_files/.pkgName/File1.jpg"

I want to get RealPathFrom content Uri. I got solution from stackoverflow and I tried below code but not working for me :

    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();
    }
  }
}

AnyOne know How to do this? I got below error for using above code. java.lang.IllegalArgumentException: column '_data' does not exist. Available columns: []

It's only not working in the Nought and oreo device because of contentUri using file provider.

Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57

1 Answers1

1

Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri. Ideally, just use that stream directly, for whatever it is that you are trying to do. Or, use that InputStream and some FileOutputStream on a file that you control to make a copy of the content, then use that file.

This is working properly in devices before Android N

Mayur Patel
  • 2,300
  • 11
  • 30