开发一个Android Auto自定义应用 [英] Develop an Android Auto custom app

查看:400
本文介绍了开发一个Android Auto自定义应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名Android开发人员,正在尝试开发自定义的Android Auto应用,该应用可以对电话屏幕进行简单的镜像。
我知道目前该API仅适用于音乐和消息传递应用程序,但是我会编写一个用于镜像的应用程序,以创建一个简单的 hello world。
我遵循Google入门教程,并且使用的是Google提供的桌面主机(DHU)(位于developer.android.com/training/auto/testing/index.html)

I'm an Android developer and I'm trying to develop a custom Android Auto app, that does a simple mirroring of the phone screen. I know that currently the API are only available for music and messaging apps, but I would write an app for mirror a simple "hello world". I follow the Google Getting Started tutorial and I'm using the Desktop Head Unit (DHU) provided by Google (at developer.android.com/training/auto/testing/index.html)

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

but when I tap last button on the bottom of the display and select "All car apps", my application doesn't appear on the list.

所有汽车应用

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

For example, if Android Auto is launched in a Samsung tablet (SM-T555), the DHU lists these app:

com.google.android.gms ,地图,系统用户界面,视频,SampleAuthenticatorService,SecureSampleAuthService,屏幕截图,Android Auto,电话,媒体,返回Google,三星计费,Google App,Google Play音乐,音乐

com.google.android.gms, Maps, System UI, Video, SampleAuthenticatorService, SecureSampleAuthService, Screen capture, Android Auto, Phone, Media, Return to Google, Samsung Billing, Google App, Google Play Music, Music

三星平板电脑中可用的汽车应用

如何制作显示在Android可用应用列表中的应用汽车?

How can I make an app that is displayed on the available app list in Android Auto? Is possible do mirroring for a custom app in Android Auto?

推荐答案

创建这样的服务:

public class HelloWorldService extends CarActivityService {

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

然后将服务添加到清单中,如下所示:

Then add the service to your manifest like this:

    <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文件:

Finally create a xml file called automotive_app_desc under your res folder:

<automotiveApp>
    <uses name="service" />
    <uses name="projection" />
    <uses name="notification" />
</automotiveApp>

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

Your HelloWorldAutoActivity.class will work as your MainActivity.

这篇关于开发一个Android Auto自定义应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆