Failed To Create Directory In Android Oreo (api 26)
I have already read the documentation for Android Oreo's Behavior and changes. I know there is different procedure to create file directory for Android Oreo (API 26) Code : File m
Solution 1:
Post Lollipop you have to ask for permission, you can look for the answer in this post here
publicbooleanisStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG,"Permission is granted");
returntrue;
} else {
Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(this, newString[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
returnfalse;
}
}
else { //permission is automatically granted on sdk<23 upon installationLog.v(TAG,"Permission is granted");
returntrue;
}
}
Permission result callback:
@OverridepublicvoidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
Log.v(TAG,"Permission: "+permissions[0]+ "was "+grantResults[0]);
//Create your Directory here
}
}
Post a Comment for "Failed To Create Directory In Android Oreo (api 26)"