Unable To Decode Stream: Java.io.filenotfoundexception (permission Denied)
I am trying to upload multiple images from gallery at once. given here. The issue i am facing is converting the string to bitmap. I got the following error. E/BitmapFactory: Unabl
Solution 1:
Add these two to Mainfest.xml
file
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Then you need to request permission before any operation dynamically like below
if (ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
// Permission is not grantedif (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block// this thread waiting for the user's response! After the user// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permissionActivityCompat.requestPermissions(thisActivity,
newString[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE);
}
}
Solution 2:
After android 6.0, only declare permissions request in AndroidManifest.Xml
is not enough, you also explicitly request corresponding permissions before doing some task.
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);
and
@OverridepublicvoidonRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case1:
{
if (grantResults.length > 0 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, do something you want
} else {
// permission denied
Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
}
return;
}
}
}
Post a Comment for "Unable To Decode Stream: Java.io.filenotfoundexception (permission Denied)"