Starting activity from service on lock screen turns on the screen but does not show the activity itself

前端 未结 3 1529
南旧
南旧 2020-12-16 00:23

I\'m trying to start an activity from a service I had already acquired the lock for as follows:

Intent i = new Intent(context, MyActivity.class);
i.setFlags(         


        
3条回答
  •  执笔经年
    2020-12-16 01:07

    I'm facing the same problem, after a lot of searching here and google, found this which unlocked the screen and popped my activity but it only works for me when the app is running (foreground/background).

    import android.view.Window;
    import android.view.WindowManager.LayoutParams;
    
    
    Window window = this.getWindow();
    window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
    

    i'm trying to start an activty when app is closed... (using broadcast receiver)

    in the docs (for example here) and most of the answers on SO the flags are added this way:

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
    

    but when i tried the way it is like in the example it unlocked the screen instead of just turning on the screen.

    hope this help . it still didn't solve my problem completely.

    EDIT:

    found this post which solved my problem.

    there is a comment there on NOT using a dialog theme which solved it for me

提交回复
热议问题