• QQ
  • nahooten@sina.com
  • 常州市九洲新世界花苑15-2

Android

ContextCompat.checkSelfPermission失效的问题

原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/Android/2019/0609/531.html

 

近来发现一个问题,我在运用ContextCompat.CheckSelfPermission()时不管若何开关权限回笼值都是PackageManager.PERMISSION_GRANTED,而运用PackageManager.checkPermission()的时候回笼值又永远都是PackageManager.PERMISSION_DENIED;

经由多番测试和查找材料发现原因:

If your application is targeting an API level before 23 (Android M) then both:ContextCompat.CheckSelfPermission and Context.checkSelfPermission doesn't work and always returns 0 (PERMISSION_GRANTED). Even if you run the application on Android 6.0 (API 23).

在targetSdkVersion小于23(Android M)的时候,ContextCompat.CheckSelfPermission 和Context.checkSelfPermission方法都不行正常事情而且永远返0(PERMISSION_GRANTED),即便你的运用运行在Android6.0(API 23)的建筑上。

办理办法:

As I said in the 1st point, if you targeting an API level before 23 on Android 6.0 then ContextCompat.CheckSelfPermission and Context.checkSelfPermission doesn't work. Fortunately you can use PermissionChecker.checkSelfPermission to check run-time permissions.  

能够运用PermissionChecker.checkSelfPermission()去检查权限是否被付与。


上篇:上一篇:Android service后台实行按时使命
下篇:下一篇:在Sqlite中通过Replace来实现插入和更新