调用需要API级别23(当前最小值为14):android.app.Activity#requestPermissions,checkSelfPermission [英] Call requires API level 23 (current min is 14): android.app.Activity#requestPermissions,checkSelfPermission
问题描述
我正在尝试添加运行时权限android(6.0.1)API 23,如果我使用SDK版本(最低版本和目标版本均为23 ),则可以正常运行,如下所示,
I am trying add run time permissions android(6.0.1) API 23,If I use SDK version(min and target version both 23) it woks fine, like below,
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23" />
如果我更改android:minSdkVersion(小于23)
If I change android:minSdkVersion(less then 23)
例如:
我在下面遇到错误:
调用需要API级别23(当前最小值为14): android.app.Activity#requestPermissions,checkSelfPermission
Call requires API level 23 (current min is 14): android.app.Activity#requestPermissions,checkSelfPermission
对于以下两种方法,
1)requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS)
2)checkSelfPermission(permission)
我尝试了ActivityCompat.checkSelfPermission()
和ContextCompat.checkSelfPermission()
都不起作用.
I tried ActivityCompat.checkSelfPermission()
and ContextCompat.checkSelfPermission()
both are not working.
我所缺少的东西无法理解.
What I missing could not understand..
推荐答案
要么检查目标> = 23,要么在方法上方添加以下行
Either check for target >=23 or simply add below line above your method
@TargetApi(Build.VERSION_CODES.M)
例如,如果要检查存储权限,则可以引用此功能,
For example, If you are checking for storage permissions, then you can refer to this function,
@TargetApi(Build.VERSION_CODES.M)
public boolean CheckStoragePermission() {
int permissionCheckRead = ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheckRead != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
ActivityCompat.requestPermissions((Activity) context,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
Define.PERMISSION_STORAGE);
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions((Activity) context,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
Define.PERMISSION_STORAGE);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
return false;
} else
return true;
}
这篇关于调用需要API级别23(当前最小值为14):android.app.Activity#requestPermissions,checkSelfPermission的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!