如何在Android中制作我们自己的锁屏而不是默认锁屏
我有一个创建我自己的手机锁应用程序的想法,类似于Android模式锁。每当手机启动/重启/手机,锁定/电话和解锁时,我都需要显示或启动我的应用程序。我不知道如何使应用程序显示而不是默认锁定屏幕并隐藏默认锁定屏幕。
所以我的问题是:
I have an idea of creating my own phone lock app similar to android pattern lock. I need to display or start my app whenever the phone boots/restarts/phone, lock/phone, and unlock. I don't know how to make the app appear instead of default lock screen and to hide the default lock screen. So my questions are:
- 如何显示或启动我的应用而不是默认锁定屏幕
-
什么是
- How to display or start my app instead of default lock screen
What is
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
这有用吗?
-
什么是
What is
public class BootReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
}
这有用吗?
- 如何显示主页我的应用程序完成其工作后?
您在第2点使用的代码应该是用作问题的答案1.参考是 Android活动超过默认锁定屏幕 。
Codes that you have used in point 2 should be used as answer of your question 1. Reference is Android activity over default lock screen.
对于问题2,请参阅以下相关链接:
For question 2, see these relevant links:
- WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
- WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
- WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
- WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
- WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
- WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
- WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
- WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
在回答你的问题3之前,我想问你,你有关于 BroadcastReceiver ?简而言之,它是 -
Before answering your question 3,i would like to ask you, do you have knowledge about BroadcastReceiver? In short it is-
广播接收器(短接收器)是一个Android组件,
允许您注册系统或申请活动。一旦发生此事件,所有
注册的事件接收者都会被Android运行时
通知。
A broadcast receiver (short receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.
例如,应用程序可以注册ACTION_BOOT_COMPLETED $一旦Android系统完成
启动过程,就会触发b $ b系统事件。
For example, applications can register for the ACTION_BOOT_COMPLETED system event which is fired once the Android system has completed the boot process.
现在回答你的问题4,您可以通过以下代码以编程方式显示主页:
Now come to your question 4, you can show home page programmatically by this code:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
参考:以编程方式进入主屏幕
最后我想为您提供一些可能对您有所帮助的链接制作自定义锁定屏幕:
And last of all i would like to provide you some links that may help you to make a custom lock screen:
- Creating an Android Lock Screen App.
- Any tutorial for customize lock screen in Android
- Making Customize Lock Screen
- Implement lock screen in Android