user3709119 user3709119 - 3 months ago 29
Android Question

Android read image files from app

I've created a simple android app that takes in 2 photos and tries its best to compare the 2. The app works fine when taking the pictures inside the app, but I'm having issues trying to load images from my phone. I want to be able to load pictures in that I've taken with my Camera and that are saved on my phone (specifically at

from the Android device). The code I have is really basic but it just consists of the following:

File file = new File(Environment.getExternalStorageDirectory(),imagePath);
Bitmap origBitmap = BitmapFactory.decodeFile(imagePath);

is null, and I am assuming it's because
is not being loaded properly. Since
is false, I assume my permissions are off. But in my manifest file I have the permission:
. I'm just not sure what I'm missing here. Thanks for any help.


Since your target is API 25, you'll need to add in runtime persmission checks to access the user's media.

See this article for more information:

Alternatively, you can goto Android Settings->Apps and find your app and manually grant the app permission to media. This should get you passed your problem, but you'll want to add the runtime permission checks if you plan on distributing the app.