我正在创建一个启动器应用程序,我想用自定义应用程序替换锁定屏幕。如何删除当前的锁定屏幕或以某种方式使其成为当我按下电源按钮ON / OFF时,它是我的自定义锁定屏幕?
这就是我的想法。我试图创建一个广播接收器来确定Screen是OFF / ON / Boot Completed。
public class LockScreenReceiver extends BroadcastReceiver {
private Intent mIntent;
public static boolean isScreenOn = true;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
isScreenOn = false;
mIntent = new Intent(context, LockScreenAppActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
isScreenOn = true;
mIntent = new Intent(context, LockScreenAppActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
mIntent = new Intent(context, LockScreenAppActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);
}
}
}
我还创建了一个服务
public class MyService extends Service {
BroadcastReceiver mReceiver;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
KeyguardManager.KeyguardLock k1;
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
k1 = km.newKeyguardLock("IN");
k1.disableKeyguard();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new LockScreenReceiver();
registerReceiver(mReceiver, filter);
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
}
@Override
public void onDestroy() {
unregisterReceiver(mReceiver);
super.onDestroy();
}
}
我遇到的问题是这不能正常工作。当我按下电源按钮时,会出现Android解锁屏幕。然后它去了我的。这是我应该通过root禁用锁定屏幕的那种情况之一,这样只有我的才会出现吗?
答案 0 :(得分:0)
事实证明,我拥有除权限之外的所有正确组件。一旦我添加了以下权限,一切都开始工作。
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
感谢Alka Jadav的参考链接。干杯!希望这对其他人有帮助。