How to get Path of image which is shared from whatsapp in android

24.4k Views Asked by At

I'm not getting Path from image from uri that I receive from whatsApp.

Uri comes like this: content://com.whatsapp.provider.media/item/66381

Image from any other apps is coming fine in my app (like facebook, twitter etc.) But its not working fine with the whatsapp.

Can anyone help me here to get the image path from it. App getting crashed in this case.

Method which I've used to get the path of the image:

private String getRealPathFromURI(Uri contentUri) {
    String result;
    String[] projection = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(mContext, contentUri, projection, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if(cursor == null){
        result = contentUri.getPath();
    }else {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);
        cursor.close();
    }
    return result;
}
0

There are 0 best solutions below