As I am developing an app for kids, I need to disable home button so that they won't close the app on class. Anyone know how to disable it in android 4.X? (The home button is a real one but not virtual button on screen)
Asked
Active
Viewed 349 times
-3
-
1did you checked http://stackoverflow.com/questions/17549478/how-to-disable-home-and-other-system-buttons-in-android – AADProgramming Mar 04 '15 at 08:52
-
1http://stackoverflow.com/questions/2068084/kiosk-mode-in-android – A.S. Mar 04 '15 at 08:52
-
http://stackoverflow.com/questions/11394843/how-can-i-disable-android-4-0-home-button – duggu Mar 04 '15 at 08:53
-
look this post answer on stackoverflow http://stackoverflow.com/questions/10077905/override-power-button-just-like-home-button – Md Hussain Mar 04 '15 at 08:55
2 Answers
0
You can't.
According to Android documentation the home button isn't delivered to applications and handled by framework.

Vadim Kotov
- 8,084
- 8
- 48
- 62

Muhannad Fakhouri
- 1,468
- 11
- 14
0
You can do that in rooted devices.
This is what I did for that:
package com.juanjovega.examples;
import android.app.Activity;
import android.os.Build;
import android.util.Log;
public class KioskActivity extends Activity {
@Override
public void onResume() {
super.onResume();
// Work around an Android 2.3 bug that sometimes causes us to become
// invisible after turning the display off and on with the power button.
setVisible(false);
setVisible(true);
}
public static void setFullScreen(boolean fullscreen) {
Process proc = null;
String ProcID = "79"; // HONEYCOMB AND OLDER
if (Build.VERSION.SDK_INT >= 14) {
ProcID = "42"; // ICS AND NEWER
}
try {
if (fullscreen) {
proc = Runtime.getRuntime().exec("su -c service call activity " + ProcID + " s16 com.android.systemui");
Log.d("kiosk", "Fullscreen mode ON");
} else {
Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
Log.d("kiosk", "Fullscreen mode OFF");
}
} catch (Exception ex) {
}
try {
proc.waitFor();
} catch (Exception ex) {
}
}
// Override the default Back key action so that we don't lose control.
@Override
public void onBackPressed() {
Log.d("kiosk", "onBackPressed");
}
public void clearHomeConfig() {
Log.d("kiosk", "clearHomeConfig");
getPackageManager().clearPackagePreferredActivities(getPackageName());
}
public void exitApp() {
// Restore UI.
setFullScreen(false);
// Clear home config.
getPackageManager().clearPackagePreferredActivities(getPackageName());
// Exit
System.exit(0);
}
}

Juanjo Vega
- 1,410
- 1
- 12
- 20
-
1I have this working (in unity3D, through a plugin), but I haven't tested it in many devices, just a nexus tablet. The device must be rooted, otherwise you can't work start/stop services, and it makes the app fullscreen, not just disables home button. It was the best option I found. – Juanjo Vega Mar 04 '15 at 12:41