I have an Android Auto app. I would like to take advantage of pagination for browsing within the app. It seems that you can set EXTRA_PAGE and EXTRA_PAGE_SIZE by getting a reference to the MediaBrowserCompat and passing those constants in .subscribe(). However, I can't figure out how to get a reference to the MediaBrowserCompat that Android Auto Audio uses in order to call .subscribe().
This seems way too complicated for something that should be simple, am I just overthinking things?
How to get the reference to the Android Auto MediaBrowser? For it, you suppose to know the package name and the class name (if you are trying to bind it outside the app). If you don't know the these details, you can just get it all from the package manager.
final Intent providerIntent =
new Intent(MediaBrowserService.SERVICE_INTERFACE);
List<ResolveInfo> mediaApps =
mPackageManager.queryIntentServices(providerIntent, 0);
for (ResolveInfo info : mediaApps) {
new MediaBrowserCompat(context,
new ComponentName(info.serviceInfo.packageName,
info.serviceInfo.name), mConnectionCallbacks, null);
}
How to set EXTRA_PAGE and EXTRA_PAGE_SIZE?
Bundle bundle = new Bundle();
bundle.putInt(MediaBrowserCompat.EXTRA_PAGE, 1);
bundle.putInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, 1);
mBrowser.subscribe("__SOME_ID__", bundle, callback);
If you are overriding the onLoadChildren() with the bundle on your service side than you have to handle the paging logic too. You can bypass it by just overriding onLoadChildren without bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With