Java 如何在android中制作我们自己的锁屏而不是默认锁屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24598612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make our own lock screen in android instead of default lock screen
提问by SreBalaji Thirumalai
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:
我有一个创建自己的手机锁应用程序的想法,类似于 android 模式锁。每当手机启动/重新启动/电话、锁定/电话和解锁时,我都需要显示或启动我的应用程序。我不知道如何使应用程序出现而不是默认锁定屏幕并隐藏默认锁定屏幕。所以我的问题是:
- 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);
- 如何显示或启动我的应用程序而不是默认锁定屏幕
什么是
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);
How this is helpful?
这有什么帮助?
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); } } } }
什么是
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); } } } }
How this is helpful?
这有什么帮助?
- How do you show the home page after my app finishes its work?
- 我的应用程序完成工作后如何显示主页?
回答by ridoy
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 点中使用的代码应用作问题 1 的答案。参考是Android 活动 over default lock screen。
For question 2, see these relevant links:
对于问题 2,请参阅以下相关链接:
- 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
Before answering your question 3,i would like to ask you, do you have knowledge about BroadcastReceiver? In short it is-
在回答你的问题 3 之前,我想问你,你对BroadcastReceiver有了解吗?简而言之就是——
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.
For example, applications can register for the ACTION_BOOT_COMPLETED system event which is fired once the Android system has completed the boot process.
广播接收器(短接收器)是一个 Android 组件,它允许您注册系统或应用程序事件。一旦该事件发生,Android 运行时就会通知该事件的所有注册接收器。
例如,应用程序可以注册 ACTION_BOOT_COMPLETED 系统事件,一旦 Android 系统完成启动过程,就会触发该事件。
Now come to your question 4, you can show home page programmatically by this code:
现在来到你的问题 4,你可以通过以下代码以编程方式显示主页:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Refer: Going to home screen programmatically
参考:以编程方式进入主屏幕
And last of all i would like to provide you some links that may help you to make a custom lock screen:
最后,我想为您提供一些可以帮助您制作自定义锁屏的链接: