show popup window on lock screen

十年热恋 提交于 2019-12-12 04:55:23

问题


I have implemented a caller ID feature where when the screen is locked it should open the lock and show the popup with the name of the person calling.

this is the code i've added in the onCreate() of the PopupActivity.

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

I've also added the permissions

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.WAKE_LOCK" />

This works fine when the phone is not password/pattern protected.However it shows a black background to the popup window when the device is password/pattern protected disabling the user from attending/rejecting the call.


回答1:


getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |PixelFormat.TRANSLUCENT);

This seems to be working for me



来源:https://stackoverflow.com/questions/45912091/show-popup-window-on-lock-screen

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