How to call listener on user click disable/allowed WRITE_EXTERNAL_STORAGE
permission ?
I want to call listener on user click deny giving WRITE_EXTERNAL_STORAGE
permission
How to call listener on user click disable/allowed WRITE_EXTERNAL_STORAGE
permission ?
I want to call listener on user click deny giving WRITE_EXTERNAL_STORAGE
permission
First I would suggest reading the post here: WRITE_EXTERNAL_STORAGE when targeting Android 10
TL:DR - Write to external storage is deprecated and doesn't work in SDK 30+
Also read this from Android.com: https://developer.android.com/about/versions/11/privacy/storage
Now the answer to your question.
You want to override the onRequestPermissionsResult() method. In your activity do something like this.
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == WRITE_EXTERNAL_STORAGE) {// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(MainActivity.this, "Write External Storage Granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Write External Storage Denied", Toast.LENGTH_SHORT).show();
}
}
}