0

所以,我按照这里的官方指南https://developer.android.com/training/auto/start/index.html创建了一个非常基本的 Android Auto Audio App。目前它什么都不做,除了声明需要在清单中声明的​​内容并实现 empty onGetRoot()and onLoadChildren()

问题是,Android Auto 应用程序无法识别它。

知道在哪里可以获得一个工作示例吗?有什么问题?

显现:

<service
    android:name=".MyService"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name=
            "android.media.browse.MediaBrowserService"/>
    </intent-filter>
</service>

auto_app_desc.xml:

<automotiveApp>
        <uses name="media" />
 </automotiveApp>

服务:

public class MyService extends MediaBrowserServiceCompat {
public static final String MEDIA_ID_ROOT = "__ROOT__";

@Override
public BrowserRoot onGetRoot(String clientPackageName, int clientUid,
                             Bundle rootHints) {

    //TODO: check if the client is allow access

    return new BrowserRoot(MEDIA_ID_ROOT, null);
}

@Override
public void onLoadChildren(final String parentMediaId,
                           final Result<List<MediaBrowserCompat.MediaItem>> result) {

    // Assume for example that the music catalog is already loaded/cached.

        List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();

    // Check if this is the root menu:
    if (MEDIA_ID_ROOT.equals(parentMediaId)) {

        // build the MediaItem objects for the top level,
        // and put them in the mediaItems list
    } else {

        // examine the passed parentMediaId to see which submenu we're at,
        // and put the children of that menu in the mediaItems list
    }
    result.sendResult(mediaItems);
}
4

2 回答 2

2

您必须转到 Android Auto 设置,在版本条目(最后一个)上点击多次以解锁开发人员设置。然后点击Developer settings菜单项并启用Unknown sources。重新启动 Android Auto,如果您的应用没问题,它将被列出。为我工作

于 2019-07-08T17:55:30.297 回答
0

我没有在清单中看到您的代码段中包含此内容,但请仔细检查该行是否也存在。

<application>
    ...
    <meta-data android:name="com.google.android.gms.car.application"
    android:resource="@xml/automotive_app_desc"/>
    ...
</application>

我创建了一个与您拥有的所有内容(加上上面的行)相匹配的示例应用程序,它出现在移动设备上的 Android Auto 以及桌面主机中。

于 2018-02-24T00:31:16.180 回答