[android][lock_screen] Unlock standby screen during incoming sip call

4.2k Views Asked by At

I am writing a sip based calling application. When there is an incoming call the corresponding activity for it is fired and is getting displayed below the lock screen. But the user doesn't get to know about the call...the lock screen comes up for a while and screen turns off..even when the call is still ringing...the ringtone is active for the entire duration but screen doesn't show the incoming call UI. I need to find a way to display the appropriate UI and keep screen on for the whole duration of incoming call...

For the part of keeping the screen on for the whole duration of incoming call I am using wakelocks...but I am not able to get rid of the lock screen...

I researched and found that can use KeygaurdManager or WindowManager.LayoutParams with appropriate flags like FLAG_KEEP_SCREEN_ON, FLAG_DISMISS_KEYGAURD, FLAG_SHOW_WHEN_LOCKED and FLAG_TURN_SCREEN_ON to unlock the phone...however these don't work in my case...I read in one of the following links that one cannot unlock the phone when the phone is password/pattern locked...is this the issue why i am unable to display the UI i want? How does it work for incoming phone calls? Please suggest me some solutions

The links that i referred to are

How can I unlock the screen programmatically in Android?

Unlock the Android Lockscreen

How do I prevent an Android device from going to sleep programmatically?

https://stackoverflow.com/questions/7006894/how-to-unlack-the-screen-and-power-on-when-my-application-is-in-background-when

Force Screen On

unlock screen while in call android

Android: Turn screen ON and notify user

How to launch an activity when lock screen is enabled?

Android activity over default lock screen

Android Create An Activity That Float Over Lockscreen

Unlock Android phone programmatically?

How to display Activity when the screen is locked?

How to unlock the device when my activity will be launched programmatically?

Android: How to turn screen on and off programmatically?

https://stackoverflow.com/questions/10590918/how-to-display-dialog-when-user-get-incoming-call-on-default-call-screen-in-andr

How to show incoming call notification in android application

How to display Activity when the screen is locked?

How to dismiss lock screen?

problem with KeyGuardManager

How unlock and lock screen programatically in android

How to unlock the device when my activity will be launched programmatically?

Get the Sip Incoming call id

How to notify SIP client when there is an incoming call on another phone

Can an activity receive an unordered broadcast(incoming call) intent before system's default receiver?

Thanks in advance.

2

There are 2 best solutions below

1
On

For me following code works well.

@Override
protected void onCreate() {
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    keyguard = km.newKeyguardLock("MyApp");
}
//when we need to unlock screen
@Override
protected void onResume() {
    keyguard.disableKeyguard();
}
@Override
protected void onPause() {
    keyguard.enableKeyguard();
}

Remember to add permission as well

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

0
On

FLAG_SHOW_WHEN_LOCKED works for me on most phones. The activity must be non-transparent (not a dialog). You might also want FLAG_TURN_SCREEN_ON and FLAG_KEEP_SCREEN_ON

However, it isn't currently working for me on a Galaxy Note running 4.0.3. Not yet sure why...