Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override android home button

Tags:

java

android

I have been searching through Android docs and stackoverflow and most of the answers I am reading say that you cannot disable or override the Android home button.

Tried - does not work

Says not possible

The problem is there are known apps that are doing this:

Kids Care

Kids Place

This is what I want:

A parent loads the app then gives device to a child. The child can only see the approved apps that are on the device (I know how to do this part). If they load an approved app from the main launcher screen on my app - if they press the home button, it takes them back to my app and not back to the device home screen. If a user presses the home button from my app - nothing should happen. Same goes for the back button.

I am looking for the proper solution in duplicating functionality of Kids Care app in overriding home button. How do I do it?

like image 287
Spentak Avatar asked Sep 12 '13 23:09

Spentak


Video Answer


2 Answers

If anyone is still interested, you could try putting this in your main activity in AndroidManifest.xml

<activity
    ...
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
        ....
    </intent-filter>
</activity>
like image 167
klifa Avatar answered Oct 24 '22 02:10

klifa


What you need to do is create your own launcher which either A) Starts another launcher or B) starts your activity. The launcher just has to be smart enough to know which to launch. So if you're in your app and you click "home" it will get into the launcher code and see that your app is running and decide to start your activity. However it it decides your app isn't running then it should start another launcher. If you remove the activity animations then it will appear seamless.

like image 33
Randy Avatar answered Oct 24 '22 00:10

Randy