关于“android.permission.WRITE_SETTINGS”的权限,如何申请,如何判断,这个很多技术达人有具体的方案:
精简代码如下:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(!Settings.System.canWrite(this)){
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, REQUEST_CODE_ASK_WRITE_SETTINGS);
}else{
有了权限,你要做什么呢?具体的动作
}
}
在这里,Write_setting有个坑,申请了write_setting权限后,也出现闪退的情况,异常为:java.lang.IllegalArgumentException: You cannot keep your settings in the secure settings.