赞
踩
我正在尝试制作一个自定义锁屏应用程序,但我不确定我是否正确地使用它.我有一个广播接收器,可以在屏幕打开时收听并启动我的锁屏活动.此接收器在服务中注册,该服务还禁用默认锁定屏幕.
问题是,屏幕打开和锁定屏幕活动显示之间有一点延迟.我该怎么做才能立刻出现?
我的服务代码:
@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;
}
和接收者:
@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);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。