【发布时间】:2021-01-07 10:57:09
【问题描述】:
当我请求权限时(在本例中为 Manifest.permission.ACCESS_FINE_LOCATION 或 "android.permission.ACCESS_FINE_LOCATION"),没有显示任何对话框并且权限总是被拒绝。当我检查 ActivityCompat.shouldShowRequestPermissionRationale 时,它也返回 false。表示用户要么从未被询问(这里的问题是什么接缝),要么被选中“不再显示”。应用信息显示“无需权限”。
我的问题与this 有关,但我已经按照答案中的建议请求了许可。
这是我的一些代码:
// firstly I call this function to check and request the permissions
private void checkPermissions(final String[] permissions) {
for(final String permission : permissions) {
if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, permission)) {
ActivityCompat.requestPermissions(this, new String[]{permission}, PERMISSION_REQUEST);
}
}
}
// This results in this callback to be called. No dialog is shown.
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST: {
for (int i = 0; i < permissions.length; i++) {
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
// The permmission is always denied ...
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[i])) {
// and we should not show a request. We always end up here
} else {
// here we should show the request again, but we dont end up here
}
}
}
}
}
}
感谢任何提示我在这里忽略的内容。
【问题讨论】:
标签: android android-permissions