Android6.0以后权限分为:危险权限,普通权限,特殊权限
危险权限列表

普通权限列表

特殊权限
SYSTEM_ALERT_WINDOW: 允许在所有的app之上弹出对话框(设置悬浮窗)
//判断系统是否拥有SYSTEM_ALERT_WINDOW权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
//没有权限跳转到授权页面
Toast.makeText(this, "can not DrawOverlays", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 1234);
} else {
//拥有权限 调用dialog,dialog中加入下面这句话
// alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("hello world").create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
dialog.show();
}
} else {
//manifest中加入<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("hello world").create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
WRITE_SETTINGS(修改系统设置)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.System.canWrite(this)) {
Toast.makeText(this, "cannot write system settings", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 1234);
} else {
Context cont = this.getApplicationContext();
Settings.System.putString(cont.getContentResolver(), "name", "Jack");
String msg = Settings.System.getString(cont.getContentResolver(), "name");
Settings.System.putInt(cont.getContentResolver(), "age", 18);
int age = Settings.System.getInt(cont.getContentResolver(), "age", 0);
String text = String.valueOf(age);
Log.d("Settings_System_String=", msg);
Log.d("Settings_System_int", text);
}
} else {
Context cont = this.getApplicationContext();
Settings.System.putString(cont.getContentResolver(), "name", "Jack");
String msg = Settings.System.getString(cont.getContentResolver(), "name");
Settings.System.putInt(cont.getContentResolver(), "age", 18);
int age = Settings.System.getInt(cont.getContentResolver(), "age", 0);
String text = String.valueOf(age);
Log.d("Settings_System_String=", msg);
Log.d("Settings_System_int", text);
}