android 点亮屏幕和屏幕解锁

下面的代码可以用来点亮屏幕
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);) T2 U" T4 z/ f) d, v" E+ A
mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer");2 a5 b/ k! E1 n' U0 d
mWakelock.acquire();
.......
mWakelock.release();
下面的代码用来屏幕解锁1 ]6 J! w) d: B  T. N4 G
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
keyguardLock.disableKeyguard();4 o* `" z; Z  q. t% P
使用这两段代码,需要在AndroidManifest文件中加入4 `! ]% D  h3 j5 t; Q4 S

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>

<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>

你可能感兴趣的:(android,service)