0

I have an image path which I am capturing from the camera in the location

file:///storage/emulated/0/Android/data/com.xxxx.xxxxx/files/Pictures/IMG_20190312_1547177544509253258561218.jpg

I am trying to display the particular image in the ImageView my code is :

        File imgFile = new  File(mMediaUri.toString());
        if(imgFile.exists()){
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
            imageView2.setImageBitmap(myBitmap);
        } else {
            Log.d("IMAGE_PATH",mMediaUri.toString());

        }

Where mMediaUri = the path which I have mentioned above. But somehow its not passing the loop from imgFile.exists(). Can you please help me in this ? Thanks in advance.

Piyush Sahay
  • 51
  • 1
  • 10

2 Answers2

0

Uri's cannot be used directly on the file constructor, Android is against passing file paths between apps.

Just use imageView2.setImageUri(mMediaUri); directly.

Reaper
  • 486
  • 3
  • 12
0

Suggestion

Why don't you use the Image viewer library for this it will manage all things for you, for example, You can use glide which will manage image path of all type - local, URL, URI etc. It will also manage Image aspect ratio too.

https://github.com/bumptech/glide