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) {
return null;
}
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) {
return new BrowserRoot(MEDIA_ID_ROOT, null);
}
@Override
public void onLoadChildren(@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
<service
android:name=".media.MusicService"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
Post a Comment for "Unable To Connect MediaBrowserCompat"