Android Auto update for 0.5.6

This commit is contained in:
exttex 2020-10-15 20:39:57 +02:00
parent c169591d41
commit ff4f5f656a

View File

@ -527,12 +527,51 @@ public class AudioService extends MediaBrowserServiceCompat {
return new BrowserRoot(MEDIA_ROOT_ID, null); return new BrowserRoot(MEDIA_ROOT_ID, null);
} }
//Create fake media item for android auto
private MediaBrowserCompat.MediaItem androidAutoPreloadMediaItem(String id, String title) {
MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
.setMediaId(id)
.setTitle(title)
.build();
return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}
@Override @Override
public void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) { public void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) {
if (listener == null) { if (listener == null) {
//Freezer not started actions
if (parentMediaId != null && parentMediaId.startsWith("__")) {
Intent intent = getPackageManager().getLaunchIntentForPackage("f.f.freezer");
//Start Freezer
if (parentMediaId.equals("__start")) {
startActivity(intent);
}
//Start with Flow
if (parentMediaId.equals("__flow")) {
intent.putExtra("preload", "flow");
startActivity(intent);
}
//Start with favorites
if (parentMediaId.equals("__favorites")) {
intent.putExtra("preload", "favorites");
startActivity(intent);
}
result.sendResult(new ArrayList<MediaBrowserCompat.MediaItem>()); result.sendResult(new ArrayList<MediaBrowserCompat.MediaItem>());
return; return;
} }
ArrayList<MediaBrowserCompat.MediaItem> out = new ArrayList<>();
//Start Freezer MediaItem
out.add(androidAutoPreloadMediaItem("__start", "Start Freezer"));
out.add(androidAutoPreloadMediaItem("__flow", "Start Flow"));
out.add(androidAutoPreloadMediaItem("__favorites", "Start Favorites"));
result.sendResult(out);
return;
}
listener.onLoadChildren(parentMediaId, result); listener.onLoadChildren(parentMediaId, result);
} }