How to disable Home button without using the TYPE_KEYGUARD?

后端 未结 7 1504
滥情空心
滥情空心 2020-12-24 03:58

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.. i

相关标签:
7条回答
  • 2020-12-24 04:34

    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.

    0 讨论(0)
  • 2020-12-24 04:40

    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);
    
    
             }
        };
    
    0 讨论(0)
  • 2020-12-24 04:42

    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

    0 讨论(0)
  • 2020-12-24 04:42

    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.

    0 讨论(0)
  • 2020-12-24 04:44

    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"
    
    0 讨论(0)
  • 2020-12-24 04:47

    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.

    0 讨论(0)
提交回复
热议问题