I am having an issue with the new permission system. I modified my code to ask permission for WRITE_EXTERNAL_STORAGE. But my app cannot write to (or read from) the sd card until I restart application (of course I allowed it in the dialog). After that it's working fine.
It's not a new app, I already declared WRITE_EXTERNAL_STORAGE in the manifest, and on earlier systems it's working fine.
I'm using checkSelfPermission and requestPermissions methods and when I make a read or write request to the sd card I've got an exception that I don't have permission.
Anyone has any idea what did I miss? Or did I run into a bug?
SDK version is the latest (updated a few hours ago), and I'm testing it on the emulator.
You need
Callback
when User allowWRITE_EXTERNAL_STORAGE
permission fromRuntimePermission dialog
.First you need to implement
OnRequestPermissionsResultCallback
Listener
ofActivityCompat
class in yourActivity
and overridevoid onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
Method to check whether User is allowing or denying the permissionYou can do like this:
Here is
onRequestPermissionsResult()
method will be called when user allow or deny Permission from Runtime permission dialog.You can also handle situation when User has checked never show Runtime Permission dialog.
Here i have used
Snackbar
to show relevant message to user about Permission andmainLayout
is id ofActivity's Main Layout
.Hope it helps you.