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?
Related
Android M:
I am trying create/resume a service whenever the home button is pressed. The activity that is displayed when the home button is pressed should not be destroyed/paused. I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher. Is there any workaround to solve this problem?
I am trying create/resume a service whenever the home button is pressed.
Implement a home screen. Convince users to use your home screen. Tie your service into your home screen implementation.
The activity that is displayed when the home button is pressed should not be destroyed/paused
The activity that is displayed will be paused, because the HOME button always brings another activity to the foreground. The only exception is if the home screen is already in the foreground. There is nothing that you can do about this, other than write your own mobile OS.
The activity that is displayed will be destroyed if and when Android decides to terminate the process associated with that activity. You do not get a vote.
I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher.
That is because the HOME button will start an activity, not a service.
So there is no way of implementing your own launcher that does not open the Home screen?
You are welcome to implement your own customized version of Android that offers this. Then, you can put that version of Android in your own custom ROM, then convince people to use that ROM.
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.
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.
I am developing simple home screen application. So when i press home button i can
choose between native and mine home screen app. The problem is: if i set my app as default
home screen application when i restart phone i can't enter native home screen app
because it has never started so my app stands on top off stack. How can i enter
native home screen app when i restart phone if mine is default home screen app?
I have idea:
On boot, i can check the calling intent - if it contains the Home category, i will call native home screen app. Something like this:
Intent creatingIntent = getIntent();
if (creatingIntent.hasCategory(Intent.CATEGORY_HOME))
{
creatingIntent.setPackage("com.android.launcher");
creatingIntent.setComponent(new ComponentName
("com.android.launcher",
"com.android.launcher2.Launcher"));
startActivity(creatingIntent);
finish();
}
But the problem is i don't know how can i get Component name for native home screen application, can someone help?
The goal of an home app (=launcher) is to replace the native launcher, it's weird to force the cohabitation of 2 launchers. But if you success to do something like that, when you press on the home button it will launch also the Native launcher.
To answer your question, the native launcher depends of the target device. Example : samsung doesn't use the same launcher than google, so components name will be different.
Have you tried to do a broadcast receiver which launch your app at start up ? With that, you don't have to put your apps as default home app, so you conserve the choice when you press on the Home button. However, it's not a solution if a user choose your app as default app.
Maybe you can look here How to use customized screen instead of default start screen in Android?
I have created a children's app that has a child lock using a custom launcher, however I have one small problem. When the app is closed and the home button is pressed the dialog to select the default launcher is displayed. Is there are way to reset the default launcher when the app is closed?
You cannot make any particular app be the default. However, you could use PackageManager and setComponentEnabledSetting(), to disable your activity that has the HOME category. Re-enable that when the user wants to have the choice of using your home screen again.