android - How can I check permission under API level 23? -


this question has answer here:

one of app has permission record_audio , app's targetsdkversion 22. cannot check permission @ runtime. notice if install app in android 6.0 , above. users can manually deny permission in system app permissions settings. question how can check whether app grand audio permission under api level 23?

i have searched quite long time find document how check permission in android m.

i have noticed context has function checkcallingorselfpermission, it's behavior strange under android 6.0. using solution here. after manually close app permission in system app settings. result not expect.

string permission = "android.permission.record_audio"; int ret = context.checkcallingpermission(permission); 

forget mention:

minsdkversion 9 targetsdkversion 22 

edit:

i have noticed there solution upgrade v4 support lib v23. little complex upgrade v4 support lib. want solution.

in api 22 , below:

int permission = permissionchecker.checkselfpermission(context, permission);  if (permission == permissionchecker.permission_granted) {     // go } else {     // permission not granted, decide } 

in api 23 , above:

from docs:

if app needs dangerous permission, must check whether have permission every time perform operation requires permission. user free revoke permission, if app used camera yesterday, can't assume still has permission today.

to check if have permission, call contextcompat.checkselfpermission() method. example, snippet shows how check if activity has permission write calendar:

// assume thisactivity current activity int permissioncheck = contextcompat.checkselfpermission(thisactivity,         manifest.permission.write_calendar); 

if app has permission, method returns packagemanager.permission_granted, , app can proceed operation. if app not have permission, method returns permission_denied, , app has explicitly ask user permission.

https://developer.android.com/training/permissions/requesting.html


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -