android手机实现插入后拔出电源,屏幕点亮

时间:2021-01-19 14:34:04

在 frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerUI.java文件中

private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

添加

 if( (oldBatteryStatus == 2 && mBatteryStatus == 3) || (oldBatteryStatus == 3 && mBatteryStatus == 2) ){
      if(DEBUG){
          Slog.d(TAG, "---------ryan-xing-------" + "oldBatteryStatus = " +
                oldBatteryStatus + "----->" + "mBatteryStatus = " + mBatteryStatus);
      }                	
       PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE); 
       PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
       wl.acquire(1000); //1000为1s,带数值参数会自动unlock
  }

charging时,数值为2, discharging时,数值为3

如果有好的方法,请回帖, 谢谢!