此“ checkSelfPermission”函数中显示错误
这是我的代码:
private void checkBTPermissions() {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP){
int permissionCheck =
this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
permissionCheck+=this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
if (permissionCheck != 0) {
this.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1001); //Any number
}
}else{
Log.d(TAG, "checkBTPermissions: No need to check permissions. SDK version < LOLLIPOP.");
}
}
答案 0 :(得分:0)
权限检查仅在API 23(即棉花糖)中可用。
您无需在Api <23上请求权限,因为它们会在App Install中自动授予。
更多信息-
https://developer.android.com/about/versions/marshmallow/android-6.0-changes#behavior-runtime-permissions
答案 1 :(得分:0)
您在以下代码上输入错误:
var myArray = [{
id: 1,
title: 'object without variants',
variants: []
},
{
id: 2,
title: 'object with variants',
variants: [{
id: 21,
title: 'variant 1',
variants: [{
id: 23,
title: 'variant 1'
}, {
id: 24,
title: 'variant 2'
}]
}, {
id: 22,
title: 'variant 2'
}]
}
]
console.log(deleteByID(myArray, 21));
function deleteByID(array, id) {
for (var i = 0; i < array.length; i++) {
var item = array[i];
deleteItemByID(myArray, item, id, i);
}
return array;
}
function deleteItemByID(array, item, id, count) {
if (item.id == id) {
array.splice(count, 1);
return;
} else {
if (item.variants) {
if (typeof item.variants === "object") {
for (var i = 0; i < item.variants.length; i++) {
var varItem = item.variants[i];
deleteItemByID(item.variants, varItem, id, i);
}
}
}
}
}
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {}
= 21 。您只能要求API级别> 22的运行时权限。
通过将代码更改为以下内容来修复该问题:
Build.VERSION_CODES.LOLLIPOP
甚至更好的方法是使用我的kubetail:)