You can try to override KeyguardManager
KeyguardManager.KeyguardLock key; KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE); //depreciated key=km.newKeyguardLock("IN");
You should insert this into service.Go something like:
public class LockService extends Service{ BroadcastReceiver receiver; @override @SuppressWarnings("deprecation") public void onCreate(){ KeyguardManager.KeyguardLock key; KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
And then in LockscreenReceiver you have to perform this action:
public class LockscreenReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context,Intent intent){ String action=intent.getAction();
you must register or call MainActivity
startService(new Intent(this,LockscreenService.class));
To see this in action, go to https://github.com/thomasvidas/Simple-Lockscreen
source share