[英]How to remove lock screen from Android?
I am creating a launcher app and I would like to replace the lock screen with a custom one. 我正在创建一个启动器应用程序,我想用一个自定义的应用程序替换锁屏。 How can I remove the current lock screen or somehow make it so that when I press the power button ON/OFF it is my custom lock screen that appears? 如何删除当前的锁定屏幕或以某种方式使之锁定,以便在按电源按钮开/关时出现我的自定义锁定屏幕?
This is what I have thought to do. 这是我一直想做的。 I tried to create a broadcast receiver to determine if Screen is OFF/ON/Boot Completed. 我试图创建一个广播接收器,以确定屏幕是否为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);
}
}
}
I also created a service 我还创建了一个服务
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();
}
}
The issue I am running in to is that this is not working properly. 我遇到的问题是这无法正常工作。 When I press the power button, the Android unlock screen is present. 当我按下电源按钮时,将显示Android解锁屏幕。 Then it goes to mine. 然后到我的。 Is this one of those situations where I should disable lock screen through root, so that only mine will come up? 这是我应该通过root禁用锁定屏幕的情况之一,这样只有我的才会出现吗?
As it turns out I had all the correct components with exception to the permissions. 事实证明,除了权限之外,我拥有所有正确的组件。 Once I added the below permissions everything started working. 添加以下权限后,一切便开始起作用。
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Thank you to Alka Jadav for his reference links. 感谢Alka Jadav的参考链接。 Cheers! 干杯! Hopefully this will be helpful to someone else. 希望这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.