Android点亮屏幕或屏幕解锁和锁定以及其他相关权限实现代码
时间:2021-01-16 12:29:59|栏目:Android代码|点击: 次
1、Android屏幕常亮/点亮
//保持屏幕常亮
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOCK_TAG);
mWakeLock.acquire();
//释放屏幕常亮锁
if(null != mWakeLock) {
mWakeLock.release();
}
2、Android屏幕解锁和锁定
//屏幕解锁
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(LOCK_TAG);
keyguardLock.disableKeyguard();
//屏幕锁定
keyguardLock.reenableKeyguard();
3、相关权限
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
复制代码 代码如下:
//保持屏幕常亮
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOCK_TAG);
mWakeLock.acquire();
复制代码 代码如下:
//释放屏幕常亮锁
if(null != mWakeLock) {
mWakeLock.release();
}
2、Android屏幕解锁和锁定
复制代码 代码如下:
//屏幕解锁
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(LOCK_TAG);
keyguardLock.disableKeyguard();
//屏幕锁定
keyguardLock.reenableKeyguard();
3、相关权限
复制代码 代码如下:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
上一篇:android ViewPager实现自动无限轮播和下方向导圆点
栏 目:Android代码
下一篇:详解AndroidStudio JNI +Gradle3.0以上JNI爬坑之旅
本文标题:Android点亮屏幕或屏幕解锁和锁定以及其他相关权限实现代码
本文地址:http://www.codeinn.net/misctech/45931.html