Nom1fan Nom1fan - 5 months ago 147
Android Question

StandOut window not shown during incoming call when key guard is set in Marshmallow

I am using Mark Wei's incredible library StandOut in my app:
http://pingpongboss.github.io/StandOut/

What I am doing is very similar to TrueCaller App

Which is displaying my own view upon an incoming call.
This generally works great.

What is my problem?

On a very specific case:


  • On Android Marshmallow (6) only

  • When key guard lock is set ON



Then the app's StandOut window is sent back behind the incoming call window and is not shown except for a flicker for a fraction of a second.

What have I tried?

Using both these flags together:


  • FLAG_DISMISS_KEYGUARD

  • FLAG_SHOW_WHEN_LOCKED



In addition (and separately) I tried this deprecated way:

KeyguardManager.KeyguardLock mLock;
KeyguardManager mKeyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
mLock = mKeyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
mLock.disableKeyguard();


When this also failed, I tried granting my app Administrator privileges (I won't add the whole code to do it as it's long but I did it properly) and then tried this:

devicePolicyManager.setKeyguardDisabled(deviceAdmin,true);


NOTE: I want to stress again that I know this is possible since TrueCaller App Is doing it so well and does not fail on every call. Just need help to find the right way to do it.

Thanks in advance!

Answer

I have three suggestions for you to try, (not sure if they will work), but they are worth a try.

  1. try to add these flags:

    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    
  2. try to add a delay of let's say 2 seconds before you fire the StandOut window activity to make sure it is coming after the incoming call system screen (later, if this solves the issue, reduce the delay as much as possible).

  3. Also found this answer here, not sure if you have access to the window properties, but saw this solution:

    "We were also facing similar issue that the overlay was not displayed on a device with pin lock. The solution that worked for us is below:

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mParams = new LayoutParams(
            LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT,
            LayoutParams.TYPE_SYSTEM_ERROR,
            LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    

    It was

    LayoutParams.TYPE_SYSTEM_ERROR
    that made the difference."

    The question that is similar: Pop up window over Android native incoming call screen like true caller Android app

Hope that something here is helpful to you, please update if solved.

UPDATE: This was solved the issue: (adding this):

LayoutParams.TYPE_SYSTEM_ERROR

Just make sure to add this before the layout is inflated, otherwise it will do nothing.