androidalarmmanagerandroid-alarmskeyguardkeyguardlock

Can't get app to unlock keyboard programatically [None of existing solutions work!]


I have read through about 10-15 posts on Stackoverflow and all of them seem to have answers that resolved the questioner's issues but I can't seem to get those solutions to work for my case. I have an app which allows for setting an alarm and the app should wake the phone up (which it does) --> unlock the device (which it doesn't) --> show a dialog (which it does once manually unlocked)

I have the following code in the OnCreate() of the Activity which is started by the AlarmReceiver

KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();

    final Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    win.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

And within the OnReceive of the AlarmReceiver class I call the WakeLocker.acquire() method which is a static method with the following code :

public static void acquire(final Context ctx) {
    if (wakeLock != null) wakeLock.release();

    final PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
                              PowerManager.ACQUIRE_CAUSES_WAKEUP |
                              PowerManager.ON_AFTER_RELEASE, "TAG");
    wakeLock.acquire();
}

My AndroidManifest.xml contains the following permissions

android.permission.WAKE_LOCK
android.permission.DISABLE_KEYGUARD

I am using a WakefulBroadcastReceiver class to receive the broadcast and inside the onReceive i start the activity with a dialog. I have a samsung S3 with a 4.4.4 android. I am not sure if this is an API issue but I just can't get this thing working. The phone lights up and shows the lock screen, but it waits on me to unlock it before showing me the dialog. Thanks for any help in this regard.


Solution

  • I changed the theme of my app from a Dialog.ALert to DeviceDefault.NoActionbar and suddenly it started to work the way I wanted to. I probably think that showing a dialog activity on top of the keyguard is not allowed and hence the error in my case.