gpt4 book ai didi

android-auto - 开发 Android Auto 自定义应用

转载 作者:行者123 更新时间:2023-12-01 00:33:54 35 4
gpt4 key购买 nike

我是一名 Android 开发人员,我正在尝试开发一个定制的 Android Auto 应用程序,它可以简单地镜像手机屏幕。
我知道目前 API 仅适用于音乐和消息应用程序,但我会编写一个应用程序来镜像一个简单的“hello world”。
我遵循 Google 入门教程,我使用的是 Google 提供的 Desktop Head Unit (DHU)(位于 developer.android.com/training/auto/testing/index.html)

但是当我点击显示屏底部的最后一个按钮并选择“所有汽车应用程序”时,我的应用程序没有出现在列表中。

All car apps

例如,如果 Android Auto 在三星平板电脑 (SM-T555) 中启动,则 DHU 会列出以下应用:

com.google.android.gms、 map 、系统 UI、视频、SampleAuthenticatorService、SecureSampleAuthService、屏幕截图、Android Auto、电话、媒体、返回 Google、Samsung Billing、Google 应用、Google Play 音乐、音乐

Available Car Apps in a Samsung Tablet

如何制作显示在 Android Auto 可用应用列表中的应用?是否可以在 Android Auto 中为自定义应用程序进行镜像?

最佳答案

创建这样的服务:

public class HelloWorldService extends CarActivityService {

@Override
public Class<? extends CarActivity> getCarActivity() {
return HelloWorldAutoActivity.class;
}
}

然后像这样将服务添加到您的 list 中:
    <meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />

<service
android:name=".HelloWorldService"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="com.google.android.gms.car.category.CATEGORY_PROJECTION" />
<category android:name="com.google.android.gms.car.category.CATEGORY_PROJECTION_OEM" />
</intent-filter>
</service>

最后在你的 res 文件夹下创建一个名为 Automotive_app_desc 的 xml 文件:
<automotiveApp>
<uses name="service" />
<uses name="projection" />
<uses name="notification" />
</automotiveApp>

您的 HelloWorldAutoActivity.class 将作为您的 MainActivity。

关于android-auto - 开发 Android Auto 自定义应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42625017/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com