Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set EXTRA_PAGE and EXTRA_PAGE_SIZE in a MediaBrowserServiceCompat by getting reference to the Android Auto MediaBrowser?

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?

like image 729
I'm_With_Stupid Avatar asked Jul 11 '17 07:07

I'm_With_Stupid


1 Answers

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.

like image 184
Shailendra Yadav Avatar answered Oct 21 '22 09:10

Shailendra Yadav