所以,我按照这里的官方指南https://developer.android.com/training/auto/start/index.html创建了一个非常基本的Android Auto Audio App。目前它什么都不做,然后宣布需要在清单中声明什么并实现空onGetRoot()
和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>
automotive_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);
}
答案 0 :(得分:0)
我没有在清单中看到这个包含在您的代码段中,但请仔细检查此行是否也在那里。
<application>
...
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
...
</application>
我创建了一个示例应用程序,其中包含您拥有的所有内容(以及上面的行),它会在移动设备上的Android Auto以及桌面主机中显示。
答案 1 :(得分:0)
您必须转到Android自动设置,在版本条目(最后一个)上点击多次,以解锁开发者设置。然后点击开发者设置菜单项并启用未知来源。重新启动Android Auto,如果您的应用程序正常,它将被列出。为我工作