1

Can we show any widget on the lock screen as per the latest android sdk? or How we can draw a layout on lockscreen?

Reference Application: https://play.google.com/store/apps/details?id=app.medicalid.free

This application show icon on lock screen and show another activity on tapping the icon without unlocking the device.

How we can achieve this functionality?

2
  • This question isn't very clear. A quick look at that page suggests to me that they're creating their own "lock screen" to show a widget, or just using a notification. The second image shows something that is not the standard Android lock screen. Commented May 23, 2020 at 10:49
  • I need to show the application Icon or any layout on lockscreen. On tapping this icon I need to show another layout with four options without unlocking the device. How I can achieve this? Commented May 25, 2020 at 4:44

1 Answer 1

1

I installed your example app and if you want to show activity on the lock screen you can use this code:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
        {
            setShowWhenLocked(true);
            setTurnScreenOn(true);
            KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
            if(keyguardManager!=null)
                keyguardManager.requestDismissKeyguard(this, null);
        }
        else
        {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Is this code works? It did not work for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.