Android 检测权限是否已吊销

Android 检测权限是否已吊销,android,android-permissions,android-6.0-marshmallow,Android,Android Permissions,Android 6.0 Marshmallow,我正在使用根设备并尝试访问其他应用程序的权限设置。 我想知道用户对每个应用程序授予或撤销了哪些权限 这个有空吗 checkSelfPermission()可以这样做吗? 此外,如果我正在下载一个不是为m版本开发的应用程序,检测操作是否可以工作,因为我发现任何目标版本低于23的应用程序都将始终返回权限\u checkSelfPermission returning PERMISSION_为targetSdkVersion的已撤销权限授予的权限\hi以下是为android M设置权限的几个步骤,请记

我正在使用根设备并尝试访问其他应用程序的权限设置。 我想知道用户对每个应用程序授予或撤销了哪些权限 这个有空吗

checkSelfPermission()
可以这样做吗? 此外,如果我正在下载一个不是为m版本开发的应用程序,检测操作是否可以工作,因为我发现任何目标版本低于23的应用程序都将始终返回
权限\u


checkSelfPermission returning PERMISSION_为targetSdkVersion的已撤销权限授予的权限\hi以下是为android M设置权限的几个步骤,请记住,您也应该在清单文件中声明相同的权限

第一步。 声明全局变量:

public static final int MY_PERMISSIONS_REQUEST_LOCATION = 0;
第二步。 在主要活动中使用此代码

private void locationpermission() {
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(activity
            ,
            Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                Manifest.permission.ACCESS_COARSE_LOCATION)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_LOCATION: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}
第三步。 在oncreate方法中调用此方法

locationpermission();
您可以从这里调用的任何权限,以及在override方法onRequestPermissionsResult中可以得到的每个结果

谢谢


希望这能帮助您(Y)。

您好,这里是安卓M设置权限的几个步骤,请记住,您也应该在清单文件中声明相同的权限

第一步。 声明全局变量:

public static final int MY_PERMISSIONS_REQUEST_LOCATION = 0;
第二步。 在主要活动中使用此代码

private void locationpermission() {
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(activity
            ,
            Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                Manifest.permission.ACCESS_COARSE_LOCATION)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(activity,
                    new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_LOCATION: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}
第三步。 在oncreate方法中调用此方法

locationpermission();
您可以从这里调用的任何权限,以及在override方法onRequestPermissionsResult中可以得到的每个结果

谢谢

希望这对你有帮助