How can I display an Activity
or Dialog
to be visible over the lock screen?
I have already tried displaying my lock activity when screen turns on by setting various window type in Activity.onCreate()
method:
TYPE_PRIORITY_PHONE
TYPE_SYSTEM_ALERT
TYPE_KEYGUARD
and others together with SYSTEM_ALERT_WINDOW
and INTERNAL_SYSTEM_WINDOW
permissions.
My activity is visible after I unlock the device.
UPDATE:
I actually already managed to display my own Activity instead of default lock screen. It work perfectly unless you use HOME button.
You can use code in any of answers here that you think it's working. Then to prevent HOME button to work, change
TYPE_SYSTEM_ALERT
orTYPE_SYSTEM_OVERLAY
(depends on what you currently use) toTYPE_SYSTEM_ERROR
:Don't go for activity, because android will not show lock screen behind your activity for security reason, so use service instead of Activity.
Below is my code in onStartCommand of my service.
And add
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
to manifestUse this in onCreate method
Hope this will work Thanks
try using this flags to disable lock screen when the activity is started.
After API level 17 you can use
showOnLockScreen like in the example...