Disable Home Button - Android
Solution 1:
Actually you can't do this, as for a power button too. It's the system buttons, to which user must always have access, independent from apps purposes. Imagine, that your application will stuck (lag), or lost internet connection. The whole device will be blocked, because user can't return to main menu. The only way to user - is poweroff device. So that is disabled by Android system architecture. Even default call and voip apps not do this, try to follow this rule too. Also, meny vendors have different implementation of it's button by hardware, so this button have different behaviour. As for alternative, you can set your Activity to be fullscreen, and show user warning message, not close your app, when making call. Hope it helps.
Solution 2:
It's possible but your app must be signed by system key. I decompiled a wizard application and found an example of code, that disables a home button. I used this code in my wizard application but I can't guarantee that it'll be working everywhere. I checked this code on STB with Android 5, 6 and 7.
privatevoiddisableHomeButton(Context context){
ContentResolvercontentResolver= context.getContentResolver();
try {
if (Build.VERSION.SDK_INT < 17) {
Settings.System.putInt(contentResolver, Settings.System.DEVICE_PROVISIONED, 0);
} else {
Settings.Global.putInt(contentResolver, Settings.Global.DEVICE_PROVISIONED, 0);
}
Settings.Secure.putInt(contentResolver, Settings.Secure.USER_SETUP_COMPLETE, 0);
}
catch(SecurityException e){
}
}
privatevoidenableHomeButton(Context context){
ContentResolvercontentResolver= context.getContentResolver();
try {
if (Build.VERSION.SDK_INT < 17) {
Settings.System.putInt(contentResolver, Settings.System.DEVICE_PROVISIONED, 1);
} else {
Settings.Global.putInt(contentResolver, Settings.Global.DEVICE_PROVISIONED, 1);
}
Settings.Secure.putInt(contentResolver, Settings.Secure.USER_SETUP_COMPLETE, 1);
}
catch(SecurityException e){
}
}
AndroidManifest.xml
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="tv.test.wizard"android:sharedUserId="android.uid.system"><uses-permissionandroid:name="android.permission.WRITE_SECURE_SETTINGS" /><uses-permissionandroid:name="android.permission.WRITE_SETTINGS" />
....
Post a Comment for "Disable Home Button - Android"