I am currently working on an application that requires several "dangerous" permissions. So I tried adding "ask for permission" as required in Android Marshmallow(API Level 23), but couldn't find how to do it.
How can I ask for permission using new permission model in my app?
To handle runtime permission google has provided a library project. You can check this from here https://github.com/googlesamples/easypermissions
EasyPermissions is installed by adding the following dependency to your build.gradle file:
To begin using EasyPermissions, have your Activity (or Fragment) override the onRequestPermissionsResult method:
Here you will get a working example how this library works https://github.com/milon87/EasyPermission
Add the permissions to the AndroidManifest.xml
To check the Android version if it needs runtime permission or not.
Ask the user to grant the permission if not granted.
Do something if the permission was granted or not.
I use RxPermission library library for asking permission. Because it is long code which we have to write to ask permission.
Add these dependency in your
build.gradle
For multiple permission at a time you can use this. This work for me.. I got another solution. if you give your targetSdkVersion bellow 22 it works for me. and it behavior as like getting permission from manifest.xml. Tested and works for me.
For more details. Check bellow link
https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en
Starting in Android Marshmallow, we need to request the user for specific permissions. We can also check through code if the permission is already given. Here is a list of commonly-needed permissions:
Here is sample code to check for permissions:
You can use my library — NoPermission (It's just one class)
compile 'ru.alexbykov:nopermission:1.1.1'
Sample
onRequestPermissionResult:
I think api more convenient than
EasyPermissions
by Google.