我有一项启动“活动”并且屏幕保护程序已打开的服务。如何以编程方式关闭Amazon Fire TV屏幕保护程序?
第一部分解开锁屏,第二部分解开屏幕保护程序。但是,我不知道这是否可以与Amazon Fire TV屏幕保护程序一起使用,但是您可以尝试一下。
在您的活动的onReceive或onCreate方法中调用此方法。
private void wakeUpTheScreen()
{
Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
我认为您也需要此权限,但我不确定:
<uses-permission android:name="android.permission.WAKE_LOCK" />
private void turnScreenOn(Activity act) {
KeyguardManager km = (KeyguardManager) act.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
PowerManager powerManager = (PowerManager) act.getApplicationContext().getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
}
我从oncreate()调用了它,它起作用了