当前位置 : 主页 > 编程语言 > java >

Android6.0申请WRITE_SETTING权限

来源:互联网 收集:自由互联 发布时间:2021-06-28
使用Action Settings.ACTION_MANAGE_WRITE_SETTINGS 启动隐式Intent 使用 “package:” + getPackageName() 携带App的包名信息 使用 Settings.System.canWrite 方法检测授权结果 private static final int REQUEST_CODE_WRITE_SET
使用Action Settings.ACTION_MANAGE_WRITE_SETTINGS 启动隐式Intent 使用 “package:” + getPackageName() 携带App的包名信息 使用 Settings.System.canWrite 方法检测授权结果
private static final int REQUEST_CODE_WRITE_SETTINGS = 2;

private void requestWriteSettings() {
    Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
    intent.setData(Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, REQUEST_CODE_WRITE_SETTINGS);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_WRITE_SETTINGS) {
        if (Settings.System.canWrite(this)) {
            Log.i(LOGTAG, "onActivityResult write settings granted");
        }
    }
}
网友评论