Reputation: 771
I have my app having targetSDKVersion = 21 and compileSDKVersion = 21. Now for some feature i use Location Permission by declaring it in Manifest by .
When i run same application on Android M ( 6.0) and above device, my application runs fine and my application is provided permission automatically by the system due to compatibility feature applied by system since Android target SDK version is 21.
But in Android M (+) devices user new permission model is introduced because of that now user can disabled Location Permission for the application from settings.
Now it this happens.. my application gets started automatically which is fine. I can't check whether location permission is given to my app or not. Is there anyway in which I can check permission for app in compile SDK version 21. ?
If our application’s target SDK is 22 or lower: If we list a dangerous permission in manifest, the user has to grant the permission when they install the application; if they do not grant the permission, the system does not install the application at all.
But what if user has installed application and revokes a permission that is critical to our application . So should I assume we developers are at mercy of application Users ?
Thanks
Upvotes: 1
Views: 98
Reputation: 942
In android M+ you get to check if permission is granted or not and act upon it by enabling/disabling specific features in your app.
Android permissions in general are separated into Normal and Dangerous Permissions.
Normal permissions: granted automatically without need of user approval. (Just add to xml as usual).
It's the dangerous permission that requires user approval and you have to check if they are granted before anytime you get to use it to make sure that the user didn't turn it off.
This link explains it all with code snippets included: https://developer.android.com/training/permissions/requesting.html
Upvotes: 1
Reputation: 625
The runtime permisions start from api 23 , in this link you can see how to ask for it and how to see if you were granted access .
https://developer.android.com/training/permissions/requesting.html
Prior to version 23 you ask for the permisions in the menifest. you can also check the android level first with :
Integer.valueOf(android.os.Build.VERSION.SDK);
if you don't want to change your target sdk(i think you should) you can use:
ContextCompat.checkSelfPermission()
ActivityCompat.requestPermissions(),
ActivityCompat.shouldShowPermissionRequestRationale()
instead of the android developer options Hope it helps.
Upvotes: 1