Java 创建一个 Android 锁屏应用程序。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20943407/
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
Creating an Android Lock Screen App.
提问by user3047494
How to create a lock-screen app that acts as a lock for android mobile. I did find one, But it was poorly constructed code wise and if I pressed the physical home key, it unlocked, making the application pointless.
如何创建一个锁屏应用,作为安卓手机的锁。我确实找到了一个,但它的代码构造很差,如果我按下物理主页键,它会解锁,使应用程序毫无意义。
I did come across a forum stating some method of blocking home button functionality was removed in Android 4.x
我确实遇到过一个论坛,说明在 Android 4.x 中删除了一些阻止主页按钮功能的方法
Yet, I have an awesome idea for a lock-screen but no ground to get started. If anyone has any knowledge on the subject, I'd love to hear it.
然而,我对锁屏有一个很棒的想法,但没有基础。如果有人对此主题有任何了解,我很想听听。
Thanks all :-)
谢谢大家:-)
采纳答案by Kirk
Yes, it is possible. This is a simple lock screen Source Codefrom GitHub
对的,这是可能的。这是一个简单的锁屏源代码,来自 GitHub
Creating an app that works like a lock is no big deal but as you said for Home key issue, I would suggest you go on and develop the App as much as you need and the only final area you would get stuck is the home key control so, try to find some tricky way to get the control of home key and make it as an app launcher for your lock app. It is not very complicated but kinda tricky though. I will post you, if I can find any Home-key access source codes
创建一个像锁一样工作的应用程序没什么大不了的,但是正如您对 Home 键问题所说的那样,我建议您根据需要继续开发该应用程序,唯一会卡住的最后一个区域是 Home 键控制因此,尝试找到一些棘手的方法来控制主页键,并将其作为锁定应用程序的应用程序启动器。这不是很复杂,但有点棘手。如果我能找到任何 Home 键访问源代码,我会发布给你
PS:
PS:
Here is the tutorial for accessing Home Key
这是访问Home Key的教程
I found the home key override somewhere. Add these lines in the App Manifest.
我在某处找到了主页键覆盖。在 App Manifest 中添加这些行。
Following two lines will do the magic
以下两行将发挥魔力
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
and override this method in your activity
并在您的活动中覆盖此方法
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.i("Home Button","Clicked");
}
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
}
return false;
}
Keep in mind that I didn't test these codes or methods, just tried to help you (you might find some drawbacks).
请记住,我没有测试这些代码或方法,只是试图帮助您(您可能会发现一些缺点)。
PS:based on the votes I can guarantee that my suggestion is working and you can develop such app with the above help :)
PS:根据投票我可以保证我的建议是有效的,你可以在上面的帮助下开发这样的应用程序:)