如何在不使用 TYPE_KEYGUARD 的情况下禁用主页按钮?

发布于 2024-12-07 03:34:35 字数 914 浏览 1 评论 0原文

我创建一个锁屏应用程序,我需要禁用主页按钮,因此如果该手机被盗,则无法访问该手机..我的锁屏是全屏活动..我使用此代码禁用主页按钮,但它给了我一些错误。这是代码:

    @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)

enter image description here

after i turn off my screen from power button and turn it on again:
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

玩世 2024-12-14 03:34:35

对于我的手机,TYPE_KEYGUARD 似乎覆盖了全屏,没有标题栏主题。通知栏始终存在。试试这个:

@Override
public void onAttachedToWindow()
{  
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);     
    super.onAttachedToWindow();  
}

让您的视图拉伸整个屏幕,它将覆盖通知区域。您的通知区域可能仍然是可点击的(不可见的),但我相信如果您捕获视图上的所有关键事件,它不应该传播到通知栏。

For my phone TYPE_KEYGUARD seems to override the fullscreen, no titlebar theme. The notification bar is always present. Try this:

@Override
public void onAttachedToWindow()
{  
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);     
    super.onAttachedToWindow();  
}

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.

悸初 2024-12-14 03:34:35

这是针对上述问题的工作。

@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
    }

添加 android.permission.DISABLE_KEYGUARD 权限并将 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 授予应用

This is the working for the above issue..

@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
    }

Add android.permission.DISABLE_KEYGUARD permission and give android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to Application

黑白记忆 2024-12-14 03:34:35

在我的 Samsung Pocket 中,上述任何操作都无法正常工作。经过进一步的搜索,我终于可以做到了。

我将全屏它们放在您的 AndroidMainfest.xml 中,如下所示(不在活动代码中):

<activity
    android:name=".geo.activity.LockActivity"
    android:theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen" />

并在您的活动中使用 keygurad onAttachedToWindow() 方法:

@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
}

正是我想要的。关闭/打开后阻止 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):

<activity
    android:name=".geo.activity.LockActivity"
    android:theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen" />

And use keygurad onAttachedToWindow() method in your activity:

@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
}

Exactly what I have wanted. Blocking HOME button and same after turning off/on.

拿命拼未来 2024-12-14 03:34:35

很简单,您应该在 onAttachedToWindow() 方法中禁用键盘保护:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

It's very simple, you should disable keyguard in the onAttachedToWindow() method:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
寒冷纷飞旳雪 2024-12-14 03:34:35

试试这个代码:

@Override
 public void onAttachedToWindow() {
  // TODO Auto-generated method stub
     super.onAttachedToWindow();  

     handler.postDelayed(mUpdateUiMsg, 100);

 }


 public boolean onKeyDown(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  if(keyCode==KeyEvent.KEYCODE_BACK){
   return true;
  }
  if(keyCode==KeyEvent.KEYCODE_HOME){
   return true;
  }

  return super.onKeyDown(keyCode, event);
 }


 private Runnable mUpdateUiMsg = new Runnable() {
        public void run() {


            getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);


         }
    };

Try this code :

@Override
 public void onAttachedToWindow() {
  // TODO Auto-generated method stub
     super.onAttachedToWindow();  

     handler.postDelayed(mUpdateUiMsg, 100);

 }


 public boolean onKeyDown(int keyCode, KeyEvent event) {
  // TODO Auto-generated method stub
  if(keyCode==KeyEvent.KEYCODE_BACK){
   return true;
  }
  if(keyCode==KeyEvent.KEYCODE_HOME){
   return true;
  }

  return super.onKeyDown(keyCode, event);
 }


 private Runnable mUpdateUiMsg = new Runnable() {
        public void run() {


            getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);


         }
    };
硪扪都還晓 2024-12-14 03:34:35

对于锁屏,为什么不直接使用以下内容:

@Override
public void onAttachedToWindow() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}

如果用户没有设置安全锁屏,则当您的应用程序关闭时,应用程序将转到主屏幕。如果用户确实设置了安全锁屏,那么无论您的应用程序如何关闭,接下来都会出现标准安全锁屏。我想我不会担心禁用按钮。无论如何,应该允许用户使用标准安全功能,因为它们提供的安全性比您可以从应用程序保证的安全性更高。另外,您不必花时间编码安全解锁功能。

For a lockscreen Why don't you just use the following:

@Override
public void onAttachedToWindow() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}

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.

鱼窥荷 2024-12-14 03:34:35

您无法控制Home Button的行为。它将完成其任务,您需要调整您的应用程序要求。

对于全屏,请将其添加到清单文件的活动标记中:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

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:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文