0

I'm developing a pattern lock app.
The problem is that when the phone screen is off, then my LockActivity shows to be unlocked, but when i press the mobile home key, then it works.

I want to override the home key function (as it's not working) until I enter the unlock pattern.

 @Override
  public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {

        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)||(keyCode == KeyEvent.KEYCODE_POWER)||(keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)) {

            return true; 
        }
       if((keyCode == KeyEvent.KEYCODE_HOME)){

           return true;
        }

    return false;

    }

    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_POWER ||(event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)||(event.getKeyCode() == KeyEvent.KEYCODE_POWER)) {
            //Intent i = new Intent(this, NewActivity.class);
            //startActivity(i);
            return false;
        }
         if((event.getKeyCode() == KeyEvent.KEYCODE_HOME)){


           return true;
         }
    return false;
    }

I googled, but did not get any solution.
Please help me.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Garg
  • 2,731
  • 2
  • 36
  • 47
  • you are getting lock the device with displaying some pattern if it's completed then check the device is in sleep mode or normal mode using broadcast receiver like user is active or not.If it is Inactive then lock device and after we can check user clicks on the home button or not – Hanuman Apr 28 '15 at 13:51
  • @Jared Burrows sir i want to disable home key function when screen lock it is feasible but how ? i want to know that ....... how i implement this feature in my application ( pattern lock app ) – Garg Apr 29 '15 at 10:05
  • @Rajat Agarwal: I think the only way to implement a lock screen that blocks the _Home_ key is to implement a _Home Screen_ replacement (as mentioned in my answer). See http://stackoverflow.com/questions/16049062/custom-lock-screen-implementation-techniques or http://stackoverflow.com/questions/16089525/understanding-custom-lock-implementation-on-android-via-home-screen-replacement as well. Or check this project: https://github.com/Joisar/LockScreenApp – Trinimon Apr 29 '15 at 13:54

1 Answers1

0

There is no way to override the Home key as such. There is no way to check for the Home key pressed event as well. The only possibility you have is, to write your own Home or Launcher activity. To do so implement your activity, and register it as follows in the Manifest:

<activity
    android:name=".MyNewHomeActivity"
    android:launchMode="singleInstance">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Once you have done this you can decide what to do in onCreate() or onResume(). Note that this requires your app/activity to be the default launcher.

Trinimon
  • 13,839
  • 9
  • 44
  • 60
  • 1
    hello sir, actually i want to disable home key ...... for screen lock app i have try it but not work – Garg Apr 29 '15 at 09:59
  • Disabling the _Home_ key isn't possible as well. This has been wisely chosen by Google in order to avoid that apps can simply block the whole device. However, you can implement a launcher app that fnishes itself in `onCreate()`. Being the standard Launcher app, this would somewhat be equal to ignoring the _Home_ key. – Trinimon Apr 29 '15 at 11:11
  • sir please give me alternate solution for it .....that how i can hold home key until unlock pattern in screen pattern lock app, – Garg Apr 29 '15 at 13:32