网上全是:
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "TAG");
-
-
- wakeLock.acquire();
-
- wl.release();
麻痹 根本没有什么卵用,我想了一下,不能熄屏 就只能降低亮度,来侧面达到效果。
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.System.canWrite(this)) {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + this.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
//有了权限,具体的动作
ContentResolver contentResolver = ADActivity.this.getContentResolver();
Uri uri = Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);
Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, 10);
ADActivity.this.getContentResolver().notifyChange(uri, null);
}
}就可以降低亮度,当然还有必须开一个定时器,多久没有操作在降低亮度,在dispatchTouchEvent中抬起和点击里面写。 |