Unable To Connect Mediabrowsercompat
I followed the Android official documentation on connecting MediaBrowserCompat but it's refused to connect, as a matter of fact neither onConnected(), onConnectionSuspended() or on
Solution 1:
Finally found the source of the problem. I was overriding onBind
and returning null
.
@Nullable@Override
public IBinder onBind(Intent intent) {
returnnull;
}
removing the above lines fixed it for me.
Solution 2:
You must implement two methods of MediaBrowserServiceCompat. At least:
@Nullable@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) {
returnnewBrowserRoot(MEDIA_ID_ROOT, null);
}
@OverridepublicvoidonLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
result.sendResult(null);
}
Solution 3:
onConnectionFailed()
can also be called if you fail to declare the service in the AndroidManifest file. Make sure the intent-filter is also correct. source
<serviceandroid:name=".media.MusicService"android:enabled="true"android:exported="true"tools:ignore="ExportedService"><intent-filter><actionandroid:name="android.media.browse.MediaBrowserService" /></intent-filter></service>
Post a Comment for "Unable To Connect Mediabrowsercompat"