Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Home button without using the TYPE_KEYGUARD?

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.

like image 586
Michael Frans Avatar asked Sep 28 '11 12:09

Michael Frans


3 Answers

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.

like image 187
Eric Chen Avatar answered Nov 18 '22 18:11

Eric Chen


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

like image 4
Mr Nice Avatar answered Nov 18 '22 18:11

Mr Nice


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.

like image 2
sunghun Avatar answered Nov 18 '22 19:11

sunghun