android.permission.ACCESS_COARSE_LOCATION始终返回-1

时间:2018-12-03 08:28:35

标签: android android-permissions

我的Android应用程序正在运行permsisions。我给所有permissions,但android.permission.ACCESS_COARSE_LOCATION总是返回-1。我不知道为什么会这样。

private static final String[] permissions = {
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.READ_PHONE_STATE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.CAMERA
};



if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
                ||checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
                || checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                || checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED
                || checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
            requestPermissions(permissions,0);
        } else {
           getMyPoints();
        }
    } else {
        getMyPoints();
    }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    isPermissionDenied = false;
    for(int i = 0 ; i<grantResults.length ; i++) {
        if(grantResults[i] == -1) {
            isPermissionDenied = true ;
            break;
        }
    }
    if(isPermissionDenied == true) {
    } else {
    }
}

0 个答案:

没有答案