简体   繁体   中英

Custom Lock Screen Delay When Wake

I'm trying to make a custom lock screen app, but I'm not sure if I'm going about it the right way. I have a broadcast receiver that listens to when the screen is turned on and starts my lock screen activity. This receiver is registered inside a service, which also disables the default lock screen.

The problem is, there is a slight delay between when the screen is turned on and the lock screen activity shows up. How would I go about doing it so that it shows up right away?

My code for the service:

@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver powerReceiver = new PowerReceiver();
    registerReceiver(powerReceiver, filter);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {  

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Service.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();

    return Service.START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

and the receiver:

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        Intent showScreen = new Intent(context, LockScreen.class);
        showScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(showScreen);


    }   

}

Turn your app into a home screen replacement app and when the user successfully unlocks the custom lock screen you can take them to the default home app.

You can find more info in this question and these questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM