I have a BroadcastReceiver
that starts an Activity
. If the Activity
is started while the screen is on, it displays and everything is fine. However, on ICS and JB devices (I haven't tested GB or HC but the issue doesn't exist with Froyo) if the Activity
is started while the screen is off, the lockscreen is not disabled, and the activity is not shown when the phone is unlocked (either through unlocking it manually or with the code I put in for post Froyo devices).
Why, on at least ICS and JB devices, does the lockscreen not get disabled without the mentioned code below, and why doesn't the activity show if the screen was off when the Activity
was started?
Here's the code:
In the BroadcastReceiver
:
Intent alarmAlert = new Intent(context, AlarmGoneOffActivity.class);
alarmAlert.putExtra(MyAlarmManager.ALARM_NUM_ID, alarm.ID);
alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_NO_USER_ACTION);
context.startActivity(alarmAlert);
In AlarmGoneOffActivity.onCreate()
:
setContentView(R.layout.alarm_gone_off);
final Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
//so far all of my post froyo devices (ICS and JB no more GB)
// don't bypass the lockscreen unless we use this
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
KeyguardManager myKeyGuard =
(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock myLock = myKeyGuard.newKeyguardLock("ShabbosAlarm");
myLock.disableKeyguard();
}
Edit: I would really prefer not to use KeyguardLock.disableKeyguard()
because it causes the keyguard to become disabled until KeyguardLock.reenableKeyguard()
which is inconvenient. Any solutions?
Edit2: I can now confirm that the issue only exists on ICS and above. Was something changed that prevents the keyguard from being disabled? And even if there was, why is my Activity
not showing when the screen is manually unlocked?
KeyguardLock.disableKeyguard()
works fine. It is the workaround for the problem. – Appliance