Show dialog with touch events over lockscreen in Android 2.3

后端 未结 3 1713
陌清茗
陌清茗 2021-01-12 10:56

I want to build a dialog which is visible on the lockscreen and can receive touch events. I built a window with WindowManager but only the TYPE_SYSTEM_OVE

3条回答
  •  借酒劲吻你
    2021-01-12 11:26

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

    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);
    

提交回复
热议问题