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

前端 未结 3 1527
南旧
南旧 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

    0 讨论(0)
  • 2020-12-16 01:07

    Since my application already includes a Service, this is what I do: if the screen is locked, I register a broadcast receiver (a bit simpler than this one, since it reacts only on unlocking) that starts the Activity as soon as the screen gets unlocked.

    0 讨论(0)
  • 2020-12-16 01:08

    Step 1: Add below code in your activity before

    setContentView(R.layout.activity_about_us);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
                    WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    

    Step 2: Lock your mobile than you will see activity in which you have added this code.

    You can implement this if you want to open particular screen by notification occurrence like skype call.

    0 讨论(0)
提交回复
热议问题