1

We recently added a MediaBrowserService to our app that allows Android Auto to discover and play audio content via our app on the device. This works as expected.

By default, Wear picks up and displays our "Now Playing" notification, provides basic Play/Pause funtionality, and provides a "Browse" action which is clearly communicating with our MediaBrowserService.

I'm working on adding an actual Wear sub-app to our main app and I'd like to call our own MediaBrowserService just like the Wear OS does.

However, when I call mediaBrowser.connect(), the ConnectionCallback onConnectionFailed always fires. The connection never succeeds. Debugging on the primary app, I never see a call come in to our MediaBrowserService.

Here's the related code. Is it possible to use a MediaBrowser in this way to replicate the functionality that Wear itself is capable of? Unfortunately, ConnectionCallback provides no information whatsoever to help explain why the connection attempt failed.

MediaBrowser.ConnectionCallback callback = new MediaBrowser.ConnectionCallback() {
            @Override
            public void onConnected()
            {
                super.onConnected();
            }

            @Override
            public void onConnectionFailed()
            {
                super.onConnectionFailed();
            }
        };


MediaBrowser mediaBrowser = new MediaBrowser(this, new ComponentName("main.app.package.name", "full.package.name.of.our.mediabrowserservice"), callback, null);
mediaBrowser.connect();

UPDATE

When I play audio in our app and the audio notification appears on the watch, I can see our MediaBrowserService start and the package calling "onGetRoot" is

com.google.android.wearable.app

I was assuming this was Wear OS itself but that seems to be the package name for the Android Wear app on the device. Somehow it is requesting and relaying the data to the watch and perhaps MediaBrowser simply doesn't work from an actual Wear app on the watch?

I see plenty of examples for using GoogleApiClient to communicate data between watch and phone. I was hoping to reuse our MediaBrowserService since Wear uses it by default. It seems this is not an option and I must use GoogleApiClient and a WearableListenerService if I want to have the Wear app request data from the handheld app.

Robert Nekic
  • 3,087
  • 3
  • 24
  • 36
  • may be you can look into the [UniversalMusicPlayer](https://github.com/googlesamples/android-UniversalMusicPlayer) – kaho Jul 13 '15 at 19:10
  • 1
    Yeah, I've looked at that sample app. Unfortunately, it does not contain a Wear app, just the handheld app. I can find examples of using MediaBrowser in Android, within the same app as the MediaBrowserService. But I can't find any examples of what Wear is doing; calling from outside. – Robert Nekic Jul 13 '15 at 19:18
  • I think you can not control your phone app through your wear app with the MediaBrowser. note that running the wear app native means running the wear app on another android system. May be you can look at how iHeart does that. they have an native app which launch intent on phone to start their app with a particular playlist, and let user control the playback using the system control. – kaho Jul 13 '15 at 22:45

1 Answers1

1

For now the answer to my question is "No". Presumably one can use a MediaBrowser and MediaBrowserService within the same Wear app (or possibly between two Wear apps) but you can't use a MediaBrowser on the Wear device to find and connect to a MediaBrowserService on the connected phone/tablet. The Android Wear app on the phone/tablet will use a MediaBrowser to talk to MediaBrowserServices on the phone/tablet; however, that data is passed to the notification on the Wear device via the normal Wear Data Layer.

Robert Nekic
  • 3,087
  • 3
  • 24
  • 36