Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Home button for a Car Home replacement app

I have been working on a replacement for the stock Car Home app for a bit, and I am completely stumped on how to override the Home button so that my app will be brought back to the foreground whenever the phone is docked. This is the way that Car Home works, so there must be a way.

It seems that BroadcastReceivers won't work, because the intent that is broadcast whenever the Home button is pressed will still cause the default homescreen app to launch; I cannot prevent it. I can override the Home button from within my app, but that does me no good since this needs to work when the user is outside my app. Car Home also does not do anything weird like set itself as the default homescreen app while it's running (I checked the logcat to make sure).

I've been really beating my head against the wall on this. Does anyone have any ideas, or can you at least point me in the right direction?

like image 633
BigFwoosh Avatar asked May 19 '10 03:05

BigFwoosh


2 Answers

Well, after many months I have finally found the answer to this question. The key is the "android.dock_home" metadata element, found here:

http://developer.android.com/reference/android/content/Intent.html#METADATA_DOCK_HOME

By using this in your AndroidManifest.xml, you can make your dock application become the home application temporarily. To do this, add this line to the AndroidManifest.xml inside the Activity tags for the dock app activity:

<meta-data android:name="android.dock_home" android:value="true" />

If the value is set to true, as long as your phone is docked the Home button will return you to the dock app. After undocking, the Home button will take you back to your normal home app.

like image 140
BigFwoosh Avatar answered Oct 11 '22 13:10

BigFwoosh


Unfortunately, there is no way in the public APIs to override the Home button without the user confirming it.

Your best bet would be to implement a CATEGORY_HOME Intent. This means when a user pressed Home they would be presented with the option to run the standard Home or yours and make yours the default if they wanted.

When your application was launched you could then check if the phone was docked. If the phone is not docked you could then open the standard Home screen and close your app before anything is displayed.

like image 21
Dave Webb Avatar answered Oct 11 '22 14:10

Dave Webb