Usted puede intentar anular KeyguardManager
KeyguardManager.KeyguardLock key;
KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
//depreciated
key=km.newKeyguardLock("IN");
Debe insertar esto en un service.Go como algo parecido a:
public class LockService extends Service{
BroadcastReceiver receiver;
@override
@SuppressWarnings("deprecation")
public void onCreate(){
KeyguardManager.KeyguardLock key;
KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
//depreciated
key=km.newKeyguardLock("IN");
IntentFilter filter=new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
receiver=new LockscreenReceiver();
registerReceiver(receiver,filter);
super.onCreate();
}
Y luego el LockscreenReceiver, debe implementar esta acción:
public class LockscreenReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context,Intent intent){
String action=intent.getAction();
//if the screen was recently enabled, do this:
//If the screen was just turned on or it just booted up, start your Lock Activity
if(action.equals(Intent.ACTION_SCREEN_OFF) || action.equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
después, debe registrarse o llamar al servicio en MainActivity
startService(new Intent(this,LockscreenService.class));
Para ver esto en acción, vaya a https://github.com/thomasvidas/Simple-Lockscreen
Gracias mucho por el enlace – Magakahn