Disable Home Button in Android ICS (4.0)
Asked Answered
Z

2

9

I am making a proprietary app for a company which will never release it to the Android Market (or Play Store I guess now) in Ice Cream Sandwich (Android 4.0).

I need to disable the Home so the users cannot maliciously uninstall software or delete the data that the app captures. This latest version is the first to be written in 4.0, the previous versions were written in 2.2 and 3.2.

For disabling the Home button in 2.2, I associated the app as a home replacement, so the button just reopened the app, but I can no longer use this method, as that somewhat prevents us from doing our updates to the app (we don't want to give the user the option of reselecting a Home default, as that would lead to data deletion.

The code I have for disableing the Home button in 3.2 is:

@Override
public void onAttachedToWindow() {
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
     super.onAttachedToWindow();
}

and, under onCreate:

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

But when I run the same code that worked on my 3.2 tablet, it does not work on my 4.0 tablet.

I was wondering if there is a new API or method that 4.0 has that will accomplish the same effect as I currently have in my 3.2 implementation.

Thanks for any help or direction.

Adam

Zebec answered 9/4, 2012 at 18:12 Comment(1)
Your app behaves like malware in that it takes control of the device away from the user. Android 4.0+ is designed to prevent exactly that.Sazerac
H
6

How about a workaround..

Write a second app that implements the home screen, when the home screen button is pressed this app will come to the foreground. From this app you then need to push your main app back to the foreground. The only catch is that your Home screen app must never need an update, but you should be able to update the main app freely without the tab asking to set the home launcher.

Hope that makes sense..

Hagler answered 12/4, 2012 at 6:39 Comment(4)
Your explanation did make sense, and it worked perfectly. There was only a little flicker from my main app to the home hijacker...but that is to be expected by switching apps. Upon start, I moved the hijacking app to the back, which helped reduce some of the flicker.Zebec
the user can still deselect this appAnnul
I also need the same kind of scenario , but We can exit the app using the eclipse DDMS and also the long press home button enables the task manager. is there a way we can disable the long press of home button ?Pituri
When we ran into the issue regarding the Task Manager I had to use some very iffy logic. First I created a BaseActivity class that all of my activities extended. I created a "navigateFromScreen" boolean that I would set to true each time I was switching the activities within the app and set to false OnCreate of the BaseActivity. OnPause I would check if the navigateFromScreen variable == false and if so I would restart the last activity I loaded (held by another global variable.) It worked to prevent switching to any other app, but it was a pain to fine tune.Zebec
M
0

No.... You cannot override home button for Android4.0 atleast.. using solution of "hotveryspicy" And ,If you wish to respond to the HOME button, implement a home screen.

Mainis answered 9/4, 2012 at 18:34 Comment(1)
I can't count the app as a home screen, because when we update the app the user would have the ability to select the stock Home as the launcher, which would allow for deleting sensitive data...which is the number one thing I need to avoid.Zebec

© 2022 - 2024 — McMap. All rights reserved.