Android保持屏幕常亮2种实现方法
方法一:
<uses-permission android:name="android.permission.WAKE_LOCK" />
private PowerManager powerManager = null;
private WakeLock wakeLock = null;
powerManager = (PowerManager) this.getSystemService(Service.POWER_SERVICE);
wakeLock = this.powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
//是否需计算锁的数量
wakeLock.setReferenceCounted(false);
//请求常亮,onResume()
wakeLock.acquire();
//取消屏幕常亮,onPause()
wakeLock.release();
方法二:
直接在onCreate()里,不用权限
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
以上是 Android保持屏幕常亮2种实现方法 的全部内容, 来源链接: utcz.com/z/330365.html