Starting with Android 6.0 (Android Marshmallow, API level 23), application will not be granted any permission during installation time. If your application targeting API level 23, has to ask user for a required permission at runtime.
If your application wants know the device’s location, the permission request dialog will be shown like the following.
The permission request dialog shown above will not show automatically, developer has to call manually. If user clicks “Allow”, then the requested permission will be granted otherwise no.
Suppose you application wants access the location and checks network state, then you will be declaring that in manifest file as shown. The following is the AndroidManifest.xml file.
While installing this application on mobile devices targeting below API level 23, it should show like the following.
In this case at the time of installation only the all required permissions are granted to the user. If your application want to know the current location of user, no need to check for the permission, application can directly access the location.
Whereas while installing this application on mobile devices targeting API level 23 (Android 6.0 or later), it should show the following.
In this case no permissions are granted at the time of installation time. But the list of permissions required to run the application will be shown in the phone’s settings application. Besides, user is also able to revoke the granted permission anytime.
In this case your application wants to know the current location of user, developer has to check whether the “ACCESS_FINE_LOCATION” and “ACCESS_COARSE_LOCATION” permissions are granted or not.
If the above permissions are not granted, then the application has to show the permission request dialog to grant the requested permission.
The code to check whether the required permission is granted or not is as follows.
Just simply declare those permissions in “AndroidManifest.xml” and it will work just fine. No need to check for the permission listed above since it couldn't be revoked.
Anyway this new Runtime Permission will work like described only when we set the application's targetSdkVersion to 23which mean it is declared that application has already been tested on API Level 23. And this feature will work only on Android 6.0 Marshmallow. The same app will run with same old behavior on pre-Marshmallow device.