嘿,我使用的是低于23的API级别。
我想在app中询问用户是否要启用阅读联系人,以便
private void checkPermissions() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_CALENDAR)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_CALENDAR)) {
Log.d("ABC", "1");
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_CALENDAR},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
}else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_CALENDAR},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
Log.d("ABC", "2");
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("ABC", "GRANTED");
} else {
Log.d("ABC", "Denied");
}
return;
}
}
}
我正在尝试使用此代码在运行时请求权限
<select id="size1"
但是,如果我不包含权限,它会自动拒绝请求,如果我这样做,则永远不需要询问。
我该怎么做才能让联系人不包含在应用程序权限中,但我可以在运行时询问它们?感谢
答案 0 :(得分:0)
无法获得Android Manifest中不存在的许可。
一个很好的例子----&gt; https://github.com/googlesamples/android-RuntimePermissions