简体   繁体   English

是否需要在运行 Android Lollipop 或更低版本的设备上检查系统权限?

[英]Is it necessary to check for system permissions on devices running Android Lollipop or lower?

If I want to check whether for example the permission to Modify System Settings is granted or not, is there any case where it's necessary below API 23?如果我想检查例如修改系统设置的权限是否被授予,在 API 23 以下是否有必要? I have this code that checks whether the permission is granted on older Android versions and I was wondering if there's any scenario where it's needed:我有这段代码可以检查是否在较旧的 Android 版本上授予了权限,我想知道是否有任何需要它的场景:

public void checkWritePermission() {
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_SETTINGS) == PackageManager.PERMISSION_DENIED) {
        try {
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_SETTINGS}, 4);
        } catch (ActivityNotFoundException activityNotFound) {
            Toast.makeText(getApplicationContext(), R.string.cant_find_system_settings, Toast.LENGTH_LONG).show();
            closeApp();
        }
    }
}

You don't need to have a permission check for the lower versions.您不需要对较低版本进行权限检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM