Getting window display from service android

房东的猫 提交于 2019-11-30 19:50:31

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"/>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!