Android 6.0中,除了危险权限不再在安装后授予,还有两个特殊权限:
- 设置悬浮窗: SYSTEM_ALERT_WINDOW
- 修改系统设置:WRITE_SETTINGS
修改系统设置权限的授权 WRITE_SETTINGS,与其他权限不同
而是使用startActivityForResult,启动系统设置的授权界面来申请
/**
* 申请权限
*/
private void requestWriteSettings()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
//大于等于23 请求权限
if ( !Settings.System.canWrite(getApplicationContext()))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE_WRITE_SETTINGS );
}
}else{
//小于23直接设置
}
}
获取授权结果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_WRITE_SETTINGS)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
//Settings.System.canWrite方法检测授权结果
if (Settings.System.canWrite(getApplicationContext()))
{
T.show("获取了权限");
}else{
T.show("您拒绝了权限");
}
}
}
}