我可以从设置中授予危险权限吗?

Can i give dangerous permissions from settings?

到目前为止,我已经 运行 了解了根设备和模拟器上的情况。我无法找到关于我是否可以 运行 我的应用程序而不编写代码来处理 运行 时间权限的明确信息。在Android M,你可以去settings/app/yourapp/permissions。在那里我可以看到 phone 的权限,在检查时,它包括 phone_state,这是一个危险的权限。如果我从那里授予权限,我的应用会自动获得权限吗?

是的,如果您从设置中授予权限,您的应用将拥有那些危险的权限。

您只需要在运行时请求危险权限,因为默认情况下您不会通过应用安装获得这些权限。

Let's understand it this way, if app is launched and tries to access the dangerous functionality, it will crash as it won't get that permission, so at that time you need to request those permissions explicitly from users, But if you manually give those dangerous permissions from settings app than your app won't need to request those permissions again explicitly at tuntime

您的应用将获得您从设置菜单授予的权限,但最好在首次启动时和开始需要这些权限的活动之前显示权限对话框。这是如何执行此操作的示例:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestAppPermissions(new
                String[]{ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.CAMERA}, REQUEST_PERMISSIONS);
    }