2

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.

Community
  • 1
  • 1
dantibb
  • 115
  • 1
  • 2
  • 9
  • 11
    How about black duct tape over the buttons? ;) – MaciejGórski May 20 '13 at 19:58
  • You cannot override the home button for security reasons. anything short of a custom rom you are SOL – tyczj May 20 '13 at 19:58
  • 2
    @tyczj you cannot override the home button but you can make your app a "launcher" that will then become your new "home" screen and take away normal functionality of the home button. This can be undone though. – TronicZomB May 20 '13 at 20:18
  • 3
    Custom ROM is going to be more reasonable on a Nexus device than some others, but it's pretty hard to beat physically framing off the illicit buttons with an enclosure. You may want to do the home screen replacement (or at least a boot receiver) anyway for launch reliability. – Chris Stratton May 20 '13 at 21:18
  • You may also be interested in my new question [here](http://stackoverflow.com/questions/17372781/home-launcher-issue-with-fragments-after-reboot). – TronicZomB Jul 01 '13 at 20:31

3 Answers3

9

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

Community
  • 1
  • 1
TronicZomB
  • 8,667
  • 7
  • 35
  • 50
  • OK, so how tricky is the custom ROM? Yes, I had considered building a mount to cover the buttons, but may be tricky to pull of in sufficiently aesthetic way (this is a photography exhibit and the app will be displaying detail from the photographs as well as text). – dantibb May 20 '13 at 20:29
  • I never looked into custom ROMs truthfully. I would expect it to be difficult and require a hefty computer for compiling. – TronicZomB May 20 '13 at 20:33
  • 1
    OK, so my 2 weeks of java experience and under-powered work laptop probably not ideal then ;-) – dantibb May 20 '13 at 20:38
  • Yea... I'm gonna guess no... I have maybe 4 months Android experience so far and I don't want to go near programming ROMs with a ten foot pole... but that's just me. You may be a little more adventurous though. – TronicZomB May 20 '13 at 20:41
  • Ha! If you would like some code for the full scree, overriding the back button, and taking control of the home button, I can provide that. Though that method is not full proof, with enough Android experience someone can get to the settings and disable the home button take over, but you can reset it again to your preference. – TronicZomB May 20 '13 at 20:45
  • 1
    Code would be great. Not too worried about someone hacking it with enough know how, just want to dissuade the casual mischief maker and accidental lay exiting out. It will be a clean device out of the box so no content other than app to worry about. – dantibb May 20 '13 at 20:48
  • Great, will give that a go, looks like I will need a decent device enclosure as well...... Now I'm going try and optimize some code with a spanner and WD40..... – dantibb May 21 '13 at 10:55
  • 1
    Setting the app to fullscreen can also be done in the manifest: `` (I can't believe this post doesn't have more votes, it's a real gem!) – Niels Sep 26 '13 at 19:43
  • 1
    @Niels Thanks for that. I had not thought about the full screen from within the manifest. I will edit that in to make this more complete. Thank you! – TronicZomB Sep 26 '13 at 20:30
4

Further to the above, which all worked great, and to make sure a comprehensive answer is out there.....

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

I got around this by change onPause app behavior to start an alarmmanager. There may be a more elegant solution, but this works.

First, create repeating alarmmanager setupAlarm(seconds)( full details here and here, note I used repeating alarm rather than one off, think both will work though) that starts your activity

then change onPause to set a 2 second alarm, so whenever someone selects the recent apps button on the nav bar, a 2 second 'alarm' to start mainActivity is set.

@Override
public void onPause() {
    setupAlarm(2);
    finish(); //optional
    super.onPause();

}

So with this and the above, any attempt to use the navigation buttons or restart the app results in app starting. So until I get round to investigating the 'kiosk' style roms this is a very good compromise.

Community
  • 1
  • 1
dantibb
  • 115
  • 1
  • 2
  • 9
0

I may be a bit late.

But i've found the, in my opinion, best solution for the Recent Apps Button Problem:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (&& !hasFocus) {
        // Close every kind of system dialog
        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);

        // send task back to front
        ActivityManager activityManager =
                (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.moveTaskToFront(getTaskId(), 0);
    }
}

The "send task back to front" part will prevent the pull down of the Notification bar by simply sending it back up instantly and will close the Recent Apps View. The other one is to close the "Shutdown/Restart" View when he tries to shut down his phone.

Now Excuse my English and have a nice Day.

Greetings Jimmy

Jimmy
  • 56
  • 6