if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.System.canWrite(this)) {
AlertDialog alertDialog1;
alertDialog1 = new AlertDialog.Builder(this)
.setTitle("申请权限")//标题
.setMessage("需要获取 修改系统设置的权限后才能运行此app,是否继续?")//内容
.setNegativeButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
})
.create();
alertDialog1.show();
}
}
添加系统权限
最新推荐文章于 2024-11-08 13:58:32 发布