how to show popup Activity or Dialog when phone is locked?

前端 未结 3 1798
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 04:36

I am trying to show a activity or a dialog when the phone is locked. I have tried using a WakeLock but it did not work and I can only see the activity once my phone is unloc

3条回答
  •  无人及你
    2021-01-03 05:23

    To show a popup on top of a lock screen try this, from my other answer:

    AlertDialog alertDialog = new AlertDialog.Builder(context).create();
            alertDialog.getWindow().setType(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
            alertDialog.show();
    

    To show activity on top of a lock screen, or basically remove the lock screen when activity is starts, try this:

    public void onCreate(Bundle savedInstanceState){
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
         ...
    }
    

    Both of those options require api 5+

提交回复
热议问题