Unlock phone programatically in Angular


#1

Is there a way to programatically unlock the phone? Or at least to display a screen similar to an alarm clock ? I’ve tried setting the flags as bellow, on my unlock event, but it doesn’t seem to work.

let activity = app.android.startActivity;
activity.getWindow().addFlags(
android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);


#2

The flags you are using are just for keeping the screen on while Activity is alive. When exactly you want to unlock the phone, upon a notification or timer?


#3

Currently I’m using a timer


#4

It’s not guaranteed that your Activity may be alive for ever once it’s paused based on system settings. You should run a background service if you want to do something in background Or AlarmManager if that suits your requirement.

Use Wakelock to unlock phone.