4

We're trying to provide an application to the mentally and physically handicapped daughter of my neighbor that let's her use an Android tablet as a Talker, i.e., she presses a few big buttons and the devices generates speech. The application is basically a WebView and an additional object in Javascript used to perform and control the speech generation, plus some logic to handle the orientation changes. Html files are generated offline for her specific layout of the talking items. We've also added some music playing and picture viewing facilities to make the device more appealing to her.

Problem is that the home button brings her back into the madness of the Android launcher screen, and that on the test device (Archos 70) the home button is not a physical button but rather shown on the touch screen itself, making it too easy to accidentally hit it.

So I'd like to return to the Android launcher only by pressing a sequence home, back, home with no other action in between.

Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?

The only clue I found so far is Overriding Home button for a Car Home replacement app, but this is rated -1 and reported to work in the emulator only. Also I doubt if I could completely abandon the original launcher, as otherwise there is no access anymore to e.g. the USB mass device control to allow new HTML files to be downloaded, the application to be killed and restarted, and so forth.

I'm willing to go for a kludge as well. Maybe a background service could be started that would bring the application to the front again as necessary?

Community
  • 1
  • 1
Wangnick
  • 735
  • 1
  • 8
  • 14
  • +1 for undertaking an admirably charitable project in (what I am assuming is) your free time – Ben Siver Jul 26 '11 at 21:43
  • 1
    Check out what they did on the [toddler app](http://stackoverflow.com/questions/4278535/disable-home-button-in-android-toddler-app). A Launcher replacement may not be so bad after all, there could be a large screen area to return her to the main portion of the app and a small area for returning the tablet to normal mode. The lock could be made too difficult for her to accidentally open. – Dan S Jul 26 '11 at 21:49
  • http://stackoverflow.com/questions/2162182/android-is-it-possible-to-disable-the-click-of-home-button – ldog Jul 26 '11 at 21:55
  • Ok, adding the following to the manifest: – Wangnick Jul 26 '11 at 22:15
  • 1
    ... makes Android ask upon home button press whether my application should become the standard home screen. Answering yes makes the Talker stick on the screen. Good. Even better, rebooting the device brings up the Talker automatically. Now how to return to the original launcher upon home, back, home? Note that I can still get out of a deadlock by using adb shell pm uninstall com.wangnick.smalltalker. – Wangnick Jul 26 '11 at 22:21

2 Answers2

4

The Home button cannot be overriden. You can write an application that responds to the home intent (that's what a launcher does) but that's all.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • I knew this but didn't try yet. Thanks to you and Dan for encouraging me to try it out. Now, how to return to the original launcher? – Wangnick Jul 26 '11 at 22:24
3

Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?

Yes. Not too deep into the innards. You can manually start a launcher by specifying the component, note that this may vary from device to device and user to user, if you're just using this privately you could hard code it, but if you release it you must allow the user to specify their real home app.

/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";

Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);

Detecting home/back/home is a bit awkard because home won't come as a onKeyEvent but instead as a new intent. Simply long-pressing the back button then display a prompt is probably a safe/good approach.

Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
  • Thanks a lot, I'll try this tomorrow (it's past midnight over here in Germany). Note that home, back, home was just an example. Search, back, search, options or so should be good as well, and are maybe preferrable over a long press popup that might confuse her. – Wangnick Jul 26 '11 at 22:37
  • Works indeed like a charm. Thanks. – Wangnick Jul 28 '11 at 09:51