yogesh sharma
yogesh sharma

Reputation: 11

Android LockScreen Widget

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?

Upvotes: 1

Views: 664

Answers (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);
        }

Upvotes: 1

Related Questions