问题
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