自定义锁屏延迟当唤醒自定义

2023-09-04 08:10:31 作者:可遇不可求

我试图使自定义锁屏应用程序,但我不知道如果我要了解它的正确途径。我有一个广播接收器监听当屏幕开启并开始我的锁屏的活动。该接收器注册一个服务,这也禁用默认锁屏内。

现在的问题是,有当屏幕开启和锁定屏幕活动显示了之间稍有延迟。我怎么会去这样做,以便它显示出来的时候了?

我的code的服务:

  @覆盖
公共无效的onCreate(){
    super.onCreate();
    IntentFilter的过滤器=新的IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver的powerReceiver =新PowerReceiver();
    registerReceiver(powerReceiver,过滤器);
}

@覆盖
公众诠释onStartCommand(意向意图,诠释标志,诠释startId){

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

    返回Service.START_STICKY;
}

@覆盖
公众的IBinder onBind(意向意图){
    返回null;
}
 

和接收器:

  @覆盖
公共无效的onReceive(上下文的背景下,意图意图){
    如果(intent.getAction()。等于(Intent.ACTION_SCREEN_ON)){
        意图showScreen =新的意图(背景下,LockScreen.class);
        showScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(showScreen);


    }

}
 

解决方案

打开你的应用程序到主屏幕更换应用程序,而当用户成功解除自定义锁屏,你可以带他们到默认主页的应用程序。

三星手机按电源键唤醒屏幕好一会才会亮,解锁后又好按,放一会儿按又不会亮了

您可以找到更多的相关信息question和这些的问题。

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.

 
精彩推荐