First of all, my permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
My methods to save and get the image:
private void saveIamgeToLocalStore(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/temp");
myDir.mkdirs();
String fname = "Profile_Image.png";
File file = new File (myDir, fname);
if (file.exists()) file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void loadImageFromLocalStore(String imageURI) {
try {
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().toString() + imageURI);
Bitmap bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(uri));
profileImage.setImageBitmap(bitmap);
profileImage.setTag("Other");
select_image_button.setText(R.string.button_remove_profile_picture);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Usage:
saveIamgeToLocalStore(BitmapFactory.decodeFile(picturePath));
loadImageFromLocalStore("/temp/Profile_Image.png");
I'm getting a
java.io.FileNotFoundException: No content provider: ...
warning.
What am I missing?
PS: The image gets saved in /mnt/sdcard/temp/
. The warning appears when loading the image.