添加系统权限

添加系统权限_第1张图片

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();
            }
        }

你可能感兴趣的:(安卓开发,android,java)