Reputation: 6867
My main goal is to show UI (With EditText, so IME support) Over the lock screen (No matter if there's PIN/Code or simple lock screen).
I know that WhatsApp application is doing it (Settings > Notification > Always show popup) so there's a solution for that.
The UI must be initialized from Service.
The view is a simple textview:
textview = new TextView(this);
textview.setText("Hello There!");
textview.setTextColor(ContextCompat.getColor(this,
android.R.color.white));
textview.setTextSize(32f);
I've tried several ways so far: (In order to reproduce like whats app i'm doing everything when screen off receiver called)
Using WindowManager
WindowManager Params:
params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); params.gravity = Gravity.BOTTOM; params.screenBrightness = 0;
Result: TextView is shown only after we unlock the device
Using Transparent activity Activity style:
true @android:color/transparent @null true true false
Also, has android:showOnLockScreen="true" attribute
Result: TextView is shown only after we unlock the device
Any other suggestions?
Thanks.
Upvotes: 1
Views: 2263
Reputation: 6426
Add this in onCreate()
of your Activity:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
Upvotes: 4