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 ?
Refer this link for full understand of multiple permission, also full source code download, click Here
Small code :
List of Android permissions normal permissions and dangerous permissions in API 23
The following methodology is about
Create a "static" class for permissions methods
In MainActivity.java
Short and sweet :). what I believe in.
Here is detailed example with multiple permission requests:-
The app needs 2 permissions at startup . SEND_SMS and ACCESS_FINE_LOCATION (both are mentioned in manifest.xml).
I am using Support Library v4 which is prepared to handle Android pre-Marshmallow and so no need to check build versions.
As soon as the app starts up, it asks for multiple permissions together. If both permissions are granted the normal flow goes.
ContextCompat.checkSelfPermission(), ActivityCompat.requestPermissions(), ActivityCompat.shouldShowRequestPermissionRationale() are part of support library.
In case one or more permissions are not granted, ActivityCompat.requestPermissions() will request permissions and the control goes to onRequestPermissionsResult() callback method.
You should check the value of shouldShowRequestPermissionRationale() flag in onRequestPermissionsResult() callback method.
There are only two cases:--
Case 1:-Any time user clicks Deny permissions (including the very first time), it will return true. So when the user denies, we can show more explanation and keep asking again
Case 2:-Only if user select “never asks again” it will return false. In this case, we can continue with limited functionality and guide user to activate the permissions from settings for more functionalities, or we can finish the setup, if the permissions are trivial for the app.
CASE -1
CASE-2
Checking every situation
if denied - showing Alert dialog to user why we need permission
Checking Permission Results