Getting window display from service android

后端 未结 2 1415
终归单人心
终归单人心 2021-01-05 07:04

I am trying to display a window from service but don\'t getting it how to do this

Here is my code--

In onStart method of Service



        
相关标签:
2条回答
  • 2021-01-05 07:43

    Key handling can also be implemented in service !! Generally if WindowManager is used to display view in service it does'nt take any key events most of the time !!

    But you can make an interface with 'dispatchKeyEvent' or any other key handling methods(onKeyUp, onKeyDown etc.) and implement them is service.

    Happy coding.

    0 讨论(0)
  • 2021-01-05 07:48

    Wooohoooo Got it work The trick was just using system window service

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.FILL_PARENT, 150,
                    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.CENTER;
    

    add the permission

     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    
    0 讨论(0)
提交回复
热议问题