0
点赞
收藏
分享

微信扫一扫

PermissUtils_getBrightnessPermiss 安卓6.0系统权限申请android.permission.WRITE_SETTINGS封装方法

素的盐 2023-03-17 阅读 21


//调用
/**
* 关闭亮度自动调节
*
* @param activity
*/
public static void stopAutoBrightness(Activity activity) {
if (!PermissUtils.getBrightnessPermiss(activity)) {
return;
}
Settings.System.putInt(activity.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}

//设置

public class PermissUtils {
public static boolean getBrightnessPermiss(Activity context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
try {

// 判断是否有WRITE_SETTINGS权限if(!Settings.System.canWrite(this))
if (!Settings.System.canWrite(context)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
Uri.parse("package:" + context.getPackageName()));
context.startActivity(intent);
} else {
return true;
}

} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

 

举报

相关推荐

0 条评论