Search code examples
javaandroidandroid-studiowear-os

Disable Back Button Samsung Smatwatch


I am developing an app that always works in the foreground for smartwatches. I use a samsung watch, it has two buttons (back and home)and i can't manage to deactivate them by code, so that i can't act on them.

Right now I have this for the back button, but it doesn't work. For the home button I don't know what to do.

@Override
public void onBackPressed() {
    super.onPause();
    ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);
    activityManager.moveTaskToFront(getTaskId(), 0);
}

could someone help me?


Solution

  • To "disable" the back button you just call the onBackPressed without it's super...

    @Override
    public void onBackPressed() {
        //super.onBackPressed();
    }
    

    About the moveTaskToFront of your code doesn't make much sense, as it is already on foreground, otherwise the onBackPressed wouldn't be called...

    About the home button, I don't think you can override it's function...