如何在不使用 TYPE_KEYGUARD 的情况下禁用主页按钮?
我创建一个锁屏应用程序,我需要禁用主页按钮,因此如果该手机被盗,则无法访问该手机..我的锁屏是全屏活动..我使用此代码禁用主页按钮,但它给了我一些错误。这是代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
该代码给了我一些错误,例如通知/状态区域,即使我在全屏模式下的活动仍然可以访问,如果我关闭显示器并再次打开它..错误是这样的:
第一次应用程序启动:(仍然没有问题)
在我通过电源按钮关闭屏幕并再次打开它之后:
主要问题出在锁屏上。当仍然可以访问通知区域时,则锁屏是没用..
知道如何解决这个问题吗?请帮助..
当我按下结束键按钮时,我也面临同样的问题。
i create a lockscreen application and i need to disable a home button, so if that phone is stolen, that phone can't be accessed.. my lockscreen is a fullscreen activity.. im use this code to disable a home button, but it gave me some bug. here's the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
that code gave me some bug like a notification/status area still can be accessed even my activity on the full screen mode, if i turn off my display and turn on it again.. the bug is like this :
first time application started: (still no problem)
after i turn off my screen from power button and turn it on again:
the main problem is on the lockscreen.. when the notification area still can be accessed, then the lockscreen is not useful..
any idea how to solve this?? please help..
I am also facing the same problem when i press the end key button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对于我的手机,TYPE_KEYGUARD 似乎覆盖了全屏,没有标题栏主题。通知栏始终存在。试试这个:
让您的视图拉伸整个屏幕,它将覆盖通知区域。您的通知区域可能仍然是可点击的(不可见的),但我相信如果您捕获视图上的所有关键事件,它不应该传播到通知栏。
For my phone TYPE_KEYGUARD seems to override the fullscreen, no titlebar theme. The notification bar is always present. Try this:
Make your view stretch the entire screen and it will cover up the notification area. Your notification area may still be clickable (invisibly) but I believe if you catch all the key events on your view it should not propagate down to the bar.
这是针对上述问题的工作。
添加
android.permission.DISABLE_KEYGUARD
权限并将android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
授予应用This is the working for the above issue..
Add
android.permission.DISABLE_KEYGUARD
permission and giveandroid:theme="@android:style/Theme.NoTitleBar.Fullscreen"
to Application在我的 Samsung Pocket 中,上述任何操作都无法正常工作。经过进一步的搜索,我终于可以做到了。
我将全屏它们放在您的 AndroidMainfest.xml 中,如下所示(不在活动代码中):
并在您的活动中使用 keygurad onAttachedToWindow() 方法:
正是我想要的。关闭/打开后阻止 HOME 按钮和相同。
In my Samusung Pocket, nothing above worked fine. I could make it finally after further search.
I put full screen them in your AndroidMainfest.xml like following (not in Acitivity code):
And use keygurad onAttachedToWindow() method in your activity:
Exactly what I have wanted. Blocking HOME button and same after turning off/on.
很简单,您应该在 onAttachedToWindow() 方法中禁用键盘保护:
It's very simple, you should disable keyguard in the onAttachedToWindow() method:
试试这个代码:
Try this code :
对于锁屏,为什么不直接使用以下内容:
如果用户没有设置安全锁屏,则当您的应用程序关闭时,应用程序将转到主屏幕。如果用户确实设置了安全锁屏,那么无论您的应用程序如何关闭,接下来都会出现标准安全锁屏。我想我不会担心禁用按钮。无论如何,应该允许用户使用标准安全功能,因为它们提供的安全性比您可以从应用程序保证的安全性更高。另外,您不必花时间编码安全解锁功能。
For a lockscreen Why don't you just use the following:
If the user doesn't have a secure lock screen set, the app will just go to the home screen when your app closes. If the user does have a secure lockscreen set then the standard secure lockscreen will come up next no matter how your app closes. I guess I wouldn't worry about disabling the buttons. The user should be allowed to use the standard security features anyways, because they provide more security then you can guarantee from your app. Plus you don't have to spend the time coding secure unlock features.
您无法控制
Home Button
的行为。它将完成其任务,您需要调整您的应用程序要求。对于全屏,请将其添加到清单文件的活动标记中:
You can not control the behaviour of
Home Button
. It will do it's task and you need to adjust your app requirements.For full screen add this in your activity tag in your manifest file: