压倒一切的Home键为汽车之家更换应用程序之家、应用程序、汽车、Home

2023-09-12 22:49:49 作者:陪衬!

我一直在努力替代了一点股票车回家的应用程序,而我就如何覆盖主页按钮,这样我的应用程序将被带回每当手机对接的前景完全难住了。这是汽车之家的工作方式,因此必须有办法。

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.

看来BroadcastReceivers是行不通的,因为其目的是无论何时播出的Home键是pressed仍然会导致默认主屏幕应用程序启动;我不能prevent它。我可以从我的应用程序覆盖主页按钮,但确实我没有好,因为这需要工作,当用户超​​出我的应用程序。汽车之家也喜欢将自己设置为默认主屏幕应用程序,而它的运行不会做任何事情奇怪(我查了logcat的,以确保)。

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?

推荐答案

好了,很多个月后,我终于找到了这个问题的答案。关键是android.dock_home元数据元素,在这里找到:

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

通过在AndroidManifest.xml中使用,你可以让你的应用程序坞成为家庭应用暂时的。要做到这一点,这一行添加到AndroidManifest.xml中的活动标签内的码头应用活动:

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" />

如果该值设置为true,只要你的手机停靠在主页按钮即可返回到码头的应用程序。脱开后,Home键将带你回到你的普通家庭的应用程序。

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.