I know that Android 6.0 has new permissions and I know I can call them with something like this
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[] {
Manifest.permission.WRITE_EXTERNAL_STORAGE
}, PERMISSION_WRITE_STORAGE);
}
Today I saw a Google app which needs 3 permissions: contacts, sms and camera. It's making a page 1-3 and calls them all together at the same time to activate.
Can anybody tell me how I can call 4 permissions to activate at the same time like sms, camera, contacts and storage?
Example (forgot the name of the google app :( )
The app needs sms,contacts and camera
the app asked me (and made a dialog page1-3) activate sms, activate contacts and then camera. So this google app was calling all 3 required permissions together and my question is how can i achive the same ?
It's easy, do this way
In your onCreate
Then check result
My handler class for request multiple permissions. You can check the full using here
Check the "Asking for multiple permissions at a time" section in this article:
Things you need to know about Android M permissions
It's very well explained, and may also touch other related topics you haven't think about.
Use helper like this (permissions names do not matter).
}
My approach is based on Nicks' answer and hopefully is a bit more usable for multiple (as many as needed, not only two) permissions. It suggests adding single-responsibility PermissionsHelper class:
}
If one or several required permissions have not been granted by user, the detailed AlertDialog message will be shown to him.
Example of usage in Activity:
Hope that this will be useful for someone.