Reputation: 55
Android 6.0 - Marshmallow
I just want to open the gallery and pick an image but I have the error :
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Download/my_image-1.png: open failed: EACCES (Permission denied)
Here is my permissions declaration in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And here is my image picker :
((Button)view.findViewById(R.id.button_Logo)).setOnClickListener(new View.OnClickListener(){
@Override
public void OnClick(View v) {
Intent getIntent = new Intent(Intent.ACTION_GETCONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getInten, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooseIntent, PICK_IMAGE);
}
});
Upvotes: 0
Views: 398
Reputation: 439
For API 23+ you need to request the read/write permissions even if they are already in your manifest.
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
}
}
Upvotes: 1
Reputation: 439
Ok , please remove this line "getintent.setType(images/*)" from your intent. And make a single intent like this...
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(i,
"Select Picture"), PICK_IMAGE_REQUEST);
Upvotes: 0
Reputation: 1963
Add the two below permissions in manifest
android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_EXTERNAL_STORAGE
Upvotes: 0