Intercepting home button on Android - android

I've researched this a lot and it seems that after ICS normal applications can no longer intercept the Home Button.
However, I see apps like Go Locker that are able to trap the Home Button.
If Go Locker isn't intercepting the home button, what are they doing to prevent the user from going to the home screen?

You cannot intercept the home button. You cannot disable it. The way how the go locker does it is by drawing its layout over other apps. It requires extra permission. See this link for more details here.

Related

What method logical for lock my home screen button android

I'm making a lock screen application on Android, I've gotten an event when the home button is pressed but I can't figure out how or what method to prevent the user from exiting the application via the Home button..
I use the method when the Home button is pressed then call the application back but this way there is a delay and still exits the application, maybe someone knows and can give me a little idea or technical for this case..
Thanks in advance..
here my button home event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:homekey
my recent app event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:recentapps
You can't. The home button is a system button, there is no way to override the behavior of it. This is because any app that prevents you leaving it, other than a kiosk app, is pretty much malware by definition- you should never prevent the user from leaving your app. And if you're building a kiosk app, you'd be making it a launcher (I'd also highly recommend not using React Native for that, as the performance is low and a launcher needs to be lightweight to lead quickly.

How to intercept HOME button similar to Nova Launcher?

I have a requirement to make a kiosk application and I need to handle HOME button and change the behavior of my application.
My application is already a launcher app but I need to consume the HOME button.
I see that Nova Launcher is doing a similar thing, they have added custom actions on click of HOME button.
Does anyone know how are they doing it?

How to hide system alert window (displays on Top of others) when user presses home button

Hi My service displays a system alert window which displays on top of all other activities similar to how facebook displays chatheads on top of other activities. This is done using WindowManager.
My problem is that I need to remove it when user presses the home button and so far I am struggling to find a way to detect home button that would work on Android Lollipop.
Any pointers would be appreciated.
Thanks
It is impossible to detect and/or intercept the HOME button from within an Android app. This is built into the system to prevent malicious apps that cannot be exited.
It's a bad idea to change the behavior of the home key. This is why Google doesn't allow you to override the home key.
You may refer this LINK for more info/discussion.

how to prevent use of HOME button in android and ios?

I am working on an application in which user should be able to use only one application,
he should not be able to switch application using HOME button,
the app. should be closed only when user presses the close button..
I have managed to override return button, don't know how to disable HOME button.
This is not possible to disable the Home Button in android When application is in the background because it might some application always disable the home button if it's possible. So this is the reason developer can't disable the home button when app in background. But In the Activity, you can intercept the home button.
In Activity you can disable the Home key in android. It work till Android 3.x only.
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
TGMCians is right.
Android will not let an activity and its services run completely alone on your device.
Using Override you can capture button clicks (home, back and menu) when your activity is in the foreground. If an activity/service has full control from the background you would not be able to switch for an incoming sms, e-mails, phone calls, etc either.
Personally I think its dangerous to override the home and back button together, if the activity hangs at some point, you can not get out of the app unless you restart the phone.
Personally, I do override the back key for exit, or return to main screen events, but leave the home button alone.
This is not possible using code at all on iOS, ever.
One usage of HOME button is for emergency situation.
Any house, apartment ... they all have an emergency method, like emergency door (exit), glass breaker (axe, bat ...); it saves life.
Similarly, on Android/iOS phone, HOME button saves users' lives (well, kind of). If HOME button is dead, the phone is considered dead as well as required an instant reboot for refresh. The button was designed for such a purpose, so that developers can't messed-up with everything.
Personally, I'm kinda of being thankful for Android/iOS framework team and whoever thought of this situation on HOME button. It saves my development so many times. I suggest you should think and consider the worst case possible if HOME button is not working in your app; for example, app fails to function as normal, HOME is disabled, so how to back to HOME screen, how to switch to other apps?...
The code provided by TGMCians is not working on 4.0+.
In case, you are working on Android framework, such as building ROMs, building frameworks for manufacturers, ... grep the source code with KEY_HOME and trace inner-depth to find how it works and disable it.
actually, it is possible to block the home button using the next methods:
use of security holes, at least on old android versions. this is done on some locker apps. i think some still work even on newer android versions, but it's a risk and it might be buggy on some devices. i know that "widgetLocker" and "Picture Password Lockscreen" try out those holes. i'm not sure how well they work now with them. best solution of becoming a lockscreen is #2 .
make your app a launcher app, which will handle the home button (user must confirm it of course). an example of such an app is "MagicLocker" , and in fact any launcher app...
using a rooted device. i have no idea how to do it, but i think it's very possible.
not quite a blocking method, but you could have your app full screen and on top (using the TYPE_SYSTEM_ALERT window layout type) , so home button won't be captured, but the user won't see what's going on behind your app. the downside is that any other button won't be captured by your app, since it's not really on the foreground.

How to set my App as default Home?

I'm developing a Android desktop app, and I would like that when it first starts it (confirm with user and) set itself as default action for Home button.
Currently, this option is given to the user by the Android system only when he first press the Home button after running my app.
Actually, I want the "back" button to not return to the default desktop, as my app will be the default desktop. Maybe the solution for this is the same of the one for the Home button?
Any idea how to do this?
You cannot do this.
Why not just let the system do it for you when the user presses the Home button for the first time. It's what the user is expecting. He/she doesn't expect it to change automatically and personally I would find that quite annoying if it did that since I like choosing my Home screen constantly.
As for the back button, simply add an onKeyDown/Up handler for the KeyEvent.KEYCODE_BACK event to return true (meaning handled by you, not the system). If you do that, it will not leave your app.

Categories

Resources