Android点亮屏幕或屏幕解锁和锁定以及其他相关权限实现代码
程序员文章站
2023-12-13 14:20:34
1、android屏幕常亮/点亮 复制代码 代码如下: //保持屏幕常亮 powermanager pm = (powermanager) getsystemservice...
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" />