disable all home button and task bar features on Nexus 7

dantibb picture dantibb · May 20, 2013 · Viewed 11k times · Source

I am building an app that will form part of an exhibition. It will be displayed on a Nexus 7 which will be securely mounted. The app has touchscreen functionality and will display interactive content.

I need to be able to disable as many features as possible whilst on display as I do not want the public to be able to get to anything other than the app.

The main thing I am struggling with is the back/home/recent app list button. I have found some examples of disabling home button (child lock Android - Is It possible to disable the click of home button ) but ideally I need the buttons to be invisible, so to turn off the 'glow' (black would be fine).

Is the bottom section on a Nexus 7 protected in some way, is there another version of Android that would allow me to do this? The Nexus device will only be used for displaying this app, no other functionality is needed.

Any suggestions would be great and very much appreciated.

Answer

TronicZomB picture TronicZomB · May 20, 2013

Your best solution without creating your own custom Android rom to remove the bottom buttons, will be to make the app full screen, override the back button, and make your app a launcher in order to override the home button.

AFAIK, there is no way of overriding the recent apps button.

Edit: One other option would to have a fullscreen app and then use a mount that will cover the buttons. (Thanks to MaciejGórski for the idea).

To make your app full screen, put the following in your activity's onCreate():

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Or you can make the app full screen from within the manifest as well, thanks to @Niels:

<application android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">

To override the back button, add this method:

@Override
public void onBackPressed() {
    return;
}

Now the home button is trickier, add the following to your manifest:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

and this to your manifest under the <activity>:

<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>

and this to your manifest under the <application>, make sure that the <receiver name> is the full package name path you define:

<receiver android:name="com.example.BootCompleteReceiver">
   <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />
   </intent-filter>
</receiver>

And lastly, create a java class file called BootCompleteReceiver, and use this code:

public class BootCompleteReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent startActivityIntent = new Intent(context, YourActivityName.class);
    startActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(parentActivityIntent);
  }
}

To later disable your app as a home screen launcher, press the recent app button, swipe down from the right side, tap settings, go to apps, then tap the upper right three dots (vertically aligned), press "Reset app preferences", and then finally press "Reset apps".

I think that should just about cover it all.

EDIT 2 I just realized/tested and you do NOT necessarily need the BOOT_COMPLETED intent if you make your application a launcher. This means that the <uses-permission>, <receiver>, and BootComplete.java are not needed. You can just use the <intent-filter> that includes the MAIN, HOME, and DEFAULT attributes.

EDIT 3 More/different information available here: Home Launcher issue with Fragments after reboot