Overriding Home button for a Car Home replacement app

﹥>﹥吖頭↗ 提交于 2019-11-28 07:05:56

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.

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.

You need to the correct intent filter in your manifest for the app to launch automatically when you dock the phone. Refer to http://developer.android.com/reference/android/content/Intent.html#CATEGORY_CAR_DOCK for the information.

I found a way to tackle HOME key. For your application set the manifest as

<action android:name="android.intent.action.MAIN" />                              
<category android:name="android.intent.category.HOME" />                                
<category android:name="android.intent.category.DEFAULT" />                            
<category android:name="android.intent.category.MONKEY"/> 

Now ur application is an alternate Launcher application.

Use the adb, and disable the launcher application using package manager

pm disable com.android.launcher2.

Now the Home key press will laways stay in the same screen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!