因此,当用户在屏幕上显示锁定屏幕时收到通知时,应该会亮起。
private void unlockScreen() {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
我有这个解锁屏幕。然后我用它来称呼它
private void updateNotification(int notificationCode)
{
switch(notificationCode)
{
case NotificationService.InterceptedNotificationCode.FACEBOOK_CODE:
shapeRoundButton.setImageResource(R.drawable.toggle_on);
unlockScreen();
break;
case NotificationService.InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE:
shapeRectangleButton.setImageResource(R.drawable.toggle_on);
break;
}
}
shapeRoundButton.setImageResource(R.drawable.toggle_on)
完全没问题,但是unlockScreen();没有按'吨。正在收到通知。
任何人都知道为什么屏幕没有解锁或我如何解锁屏幕?干杯!
答案 0 :(得分:0)
看到这个
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Log.e("screen on.................................", ""+isScreenOn);
if(isScreenOn==false)
{
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock");
wl.acquire(10000);
WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock");
wl_cpu.acquire(10000);
}