android: turn off screen when close to face

后端 未结 4 1142
情书的邮戳
情书的邮戳 2020-12-01 02:39

My app allows the user to access their corporate voice mail. Normally, durring a phone call when the user holds the device up to their ear, the screen shuts off so they wont

4条回答
  •  甜味超标
    2020-12-01 03:10

    as of API level 21 (Lollipop) you can get proximity wake lock this just like that:

    if(powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
            PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG);
            wakeLock.setReferenceCounted(false);
            return wakeLock;
        } else {
            return null;
        }
    }
    

    then it is up to you to acquire and release the lock.

    PS: PowerManager#getSupportedWakeLockFlags was hidden, but now exists nomore. They have invented isWakeLockLevelSupported instead.

提交回复
热议问题