Android 熄屏

来源:互联网 发布:金九银十原油利多数据 编辑:程序博客网 时间:2024/06/11 18:31
网上全是:
  1. PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);  
  2. PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "TAG");   
  3.   
  4. //屏幕会持续点亮  
  5. wakeLock.acquire();  
  6. //释放锁,屏幕熄灭。  
  7. 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中抬起和点击里面写。
原创粉丝点击