Android : How to show dialog or activity over lock screen[ not unlock the screen]

后端 未结 3 928
野趣味
野趣味 2020-12-23 17:58

I hava a app, it will receive msg from server and make a dialog to user.So when phone is on lock screen i want dialog will show on the top of lock screen but not unlock it.c

3条回答
  •  佛祖请我去吃肉
    2020-12-23 18:48

    Finally I achieved the same. Don't go for activity, because android will not show lock screen behind your activity for security reason, so use service instead of Activity.

    Below is my code in onStartCommand of my service

    WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    
    View mView = mInflater.inflate(R.layout.score, null);
    
    WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
    /* | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON */,
    PixelFormat.RGBA_8888);
    
    mWindowManager.addView(mView, mLayoutParams);
    

    And add to manifest

提交回复
热议问题