Search code examples
androidgear-vr

GearVR override back and home buttons


I am trying to override the back and home buttons in my GearVR app. I actually trying to completely disable them. I have tried:

@Override
public void onBackPressed() {
    Log.d(TAG, "onBackPressed: ");

}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Log.d(TAG, "onKeyLongPress: ");

    }
    return false;
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    Log.d(TAG, "onKeyUp: "+keyCode);
    if(keyCode==KeyEvent.KEYCODE_BACK){
       return false;
    }
    //return super.onKeyUp(keyCode, event);
    return false;
}

I have also looked the examples in the SamsungGearVR repo.

The only thing I have been able to capture is the onKeyLongPress but still can not override it just add to it.

The end result is I want to completely disable both back and home buttons.


Solution

  • Since Android version 4.0+, you are not able to override the home button this change was done for security purpose. You do have the option of possible disabling the home button using the screen pinning feature introduced in Android 5.0.

    For disabling the back button you have two option:

    Overriding the public void onBackPressed() or onKeyDown(int keyCode, KeyEvent event). Since overriding onBackPressed didn't work I would try onKeyDown.

    Also, it would be very helpful if you provided the segment of code that is not behaving as expected along with what the code you have tried.