1

My requirement is to create Custom LockScreen, using below link http://code.google.com/p/contactowner/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Fappengine%2Fparanoid_android%2Flost i am able to create working Fine. But my Problem is when i press HOME button it is opening the Launcher screen. (1) How to Block home button in android ? (2)If it is not possible, How few custom lock screen .apks in the android market able to block Home button.

How can i achieve that ?

Appreciate your help...

Anil Kumar
  • 1,065
  • 1
  • 13
  • 24

4 Answers4

1

actually it is possible to block the home button , as locker replacement apps do (like this one and this one) . however , they do it using a sneaky way which might not work on some devices and/or future versions of android (hint: look at the code of android OS - where and when in the entire runtime of the OS is the home button being blocked from the user?) .

that's why the best thing to do in order to do it nicely is to capture the home button by acting as a launcher . then , when it's time to unlock the locker , you call the original launcher.

another advantage of using this method is that the locker will "stay better" in the memory and will be the first one that will be launched upon bootup (no need for special permission for bootup ) .

android developer
  • 114,585
  • 152
  • 739
  • 1,270
1

You cannot intercept the key and do this unless you have access to the android source code and can change it. From an app's perspective, you can't do this unless you have the source either. Keep in mind that this is Frowned upon in android.

So the only thing you have available is onUserLeaveHint() which is a method from an Activity. But you still CANNOT stop a user from going home.

Ref:

http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint()

Here is proof that you cannot do it directly

    public static final int KEYCODE_HOME

    Since: API Level 1
    Key code constant: Home key. This key is handled by the 
framework and is never delivered to applications.
    Constant Value: 3 (0x00000003)
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • Hi JoxTraex,Thanks for quick Reply. Please try to answer my second question. Is their any other way to achieve this requirement??? – Anil Kumar Jan 19 '12 at 07:44
0

it's possible! use window params setType(TYPE_SYSTEM_ERROR) and you'll get what you want.

A. N
  • 153
  • 1
  • 15
0

JoxTraex is probably right , you shouldn't disable HOME key, or else users will report your app in future

But there is a way to detect home button press,

Check the answer to this question

Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57
  • Hi Thanks for your Reply. I tested with onAttachedToWindow() code '@Override public void onAttachedToWindow() { super.onAttachedToWindow(); this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); }'. But this will work only in HTC and Sony experia devices. Not working in Docomo,samsung devices. Any code to reach this requirement to make work in all Devices? – Anil Kumar Jan 23 '12 at 00:11