是否可以在最小SDK<上设置checkSelfPermission? 23? [英] Is it available to set checkSelfPermission on minimum SDK < 23?

查看:62
本文介绍了是否可以在最小SDK<上设置checkSelfPermission? 23?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android-M中的新运行时权限要求最低23个API级别,但我的项目中仍需要最低16 API级别.

New runtime permissions in Android-M asking for minimum 23 API level, but I still need minimum 16 API level in my project.

那么,如何使此代码更向前兼容?

So, how to make this code more forward-compatible?

致谢

推荐答案

ActivityCompat.requestPermissions() ContextCompat.checkSelfPermission()返回PackageManager.PERMISSION_GRANTED).

Use ContextCompat.checkSelfPermission(), ActivityCompat.requestPermissions(), and ActivityCompat.shouldShowPermissionRequestRationale(), from the support-v4 library (v23 or higher). These are backwards-compatible; if you are running on an older version of Android, they will "do the right thing" (e.g., return PackageManager.PERMISSION_GRANTED for ContextCompat.checkSelfPermission()).

这篇关于是否可以在最小SDK<上设置checkSelfPermission? 23?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆