androiddockandroid-homebutton

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).

What can I try next?


Solution

  • 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.