1

for example,my app requests a permission in Manifest file,like android.permission.WRITE_EXTERNAL_STORAGE,how can i check whether the permission is denied by user or some security apps?

Buffalo
  • 23
  • 1
  • 4
  • after some tests, it is better to call checkCallingPermission(permission) to check a runtime permission rather than calling checkSelfPermission(permission) – Buffalo Aug 19 '15 at 19:08

3 Answers3

2

Call context.checkCallingPermission(permission)

permission -- The name of the permission being checked, as a String

Returns PERMISSION_GRANTED if you have the permission, or PERMISSION_DENIED if not.

See checkCallingPermission

As noted in the docs and the comments, there are some subtleties here.

Stu Little
  • 21
  • 4
  • after i did some tests,i found that when my app's permission was rejected by the Clean Master,if i called checkSelfPermission(String permission),it returned PERMISSION_GRANTED,which means that this method not only checks the runtime permission ,but also checks the install permission ,so in my case,it is better to call checkCallingPermission to only check the runtime permission – Buffalo Aug 19 '15 at 18:57
0

Right now, android asks for the user to accept all the permissions an app asks for in the manifest on installation. In the upcoming M release, android will switch over to the iOS style of permissions with an "on needed" basis. (For certain permissions. See @Commonsware's comment for more details) Meaning whenever the user tries to use a feature that requires permission it will ask them to accept or deny. If they hit deny I imagine there will be an sdk positive and negative response button interface to implement.

As for right now in your dilemma, if the user rejects permissions they won't be able to use your app period.

cj1098
  • 1,560
  • 6
  • 32
  • 60
  • 3
    "In the upcoming M release, android will switch over to the iOS style of permissions with an "on needed" basis" -- [only for some permissions](http://developer.android.com/preview/features/runtime-permissions.html). `WRITE_EXTERNAL_STORAGE` happens to be one. Use `checkSelfPermission()` on `Context` on Android 6.0+ to determine if you hold a runtime permission. – CommonsWare Aug 19 '15 at 18:09
  • 1
    Thanks @CommonsWare! Love your book btw. Are you planning on releasing M related material soon? Or have you played around with the developer preview yet? – cj1098 Aug 19 '15 at 18:14
  • 1
    Thanks for the kind words! Version 6.8 will be released next week, with coverage of Android 6.0, including lots of stuff on the runtime permissions system. – CommonsWare Aug 19 '15 at 18:18
  • Is it officially 6.0? I had thought they were doing 5.2 or something like a patch release. 6.0 sounds cooler imo lol. Awesome! Your book has helped with some tough problems I've had in the past. I'm curious if you have any free time if you could check you my most recent hurdle with coordinator layout. The SO post is http://stackoverflow.com/questions/31735603/coordinator-layout-custom-layout-behavior-never-getting-called It's a doozy haha – cj1098 Aug 19 '15 at 18:22
  • @Buffalo. If a feature is blocked and it is after the installation of your app, I would assume a security app is blocking it. The only way a user could deny permission of a feature in your app is at installation time. There's another approach we could use to see if the user is blocking permissions. Check before you use a certain permission if it is available via this accepted answer http://stackoverflow.com/questions/7203668/how-permission-can-be-checked-at-runtime-without-throwing-securityexception – cj1098 Aug 19 '15 at 18:28
  • 1
    "Is it officially 6.0?" -- [as of Monday, yes](http://android-developers.blogspot.com/2015/08/m-developer-preview-3-final-sdk.html). – CommonsWare Aug 19 '15 at 18:28
  • @Buffalo no problem! If you wouldn't mind marking my answer as the correct answer, I'd greatly appreciate it :) – cj1098 Aug 19 '15 at 19:01
  • 1
    @cj1098 yeah ,no problem :) – Buffalo Aug 19 '15 at 19:10
0

You can use checkCallingPermission() to check weather the runningtime permission is denied by users or some apps.