Si può provare l'override KeyguardManager
KeyguardManager.KeyguardLock key;
KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE);
//depreciated
key=km.newKeyguardLock("IN");
È necessario inserire questo in un service.Go come qualcosa di simile:
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();
}
E poi LockscreenReceiver, è necessario implementare questa azione:
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);
}
}
}
Successivamente, è necessario registrarsi o chiamare il servizio in MainActivity
startService(new Intent(this,LockscreenService.class));
Per vedere in azione, andare a https://github.com/thomasvidas/Simple-Lockscreen
fonte
2015-11-03 16:11:51
Grazie mille per il link – Magakahn