15

I have an Android App with working Auto capabilities which has been rejected from the store because:

"Your app does not support all of the required voice commands. For example, your app does not contain an Intent filter for action "android.media.action.MEDIA_PLAY_FROM_SEARCH"."

So i looked to at least make the app respond to "play music on X app" but by looking at the documentation I can't get it to work. I added this to my main activity (which is not the launcher activity, it controls the service via binder)

<intent-filter>
  <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

which triggers a MediaBrowserServiceCompatwhich is initialized this way: manifest:

<service
            android:name=".Services.RadioService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>

part of the code:

   @Override
    public void onCreate() {
        super.onCreate();
        audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
        mSession = new MediaSessionCompat(this, "RService");
        mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS
                | MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS);
        mSession.setCallback(mCallback);
        mSessionConnector = new MediaSessionConnector(mSession);
        setSessionToken(mSession.getSessionToken());
        setMediaBrowser();
        initializeReceiver();
        C_F_App.createNotificationChannelPlayer(getApplicationContext());
        rNController = new RadioNotificationController(this, mSession, getApplicationContext());
    }

final MediaSessionCompat.Callback mCallback =
            new MediaSessionCompat.Callback() {
                @Override
                public void onPlayFromMediaId(String mediaId, Bundle extras) {
                    playForAuto(mediaId);
                }

                @Override
                public void onPlayFromSearch(String query, Bundle extras) {
                    super.onPlayFromSearch(query, extras);
                    Log.d("Test", "Test");
                }

                @Override
                public void onStop() {
                    playPause();
                }

                @Override
                public void onPlay() {
                    playPause();
                }

                @Override
                public void onPause() {
                    playPause();
                }
            };

public void setMediaBrowser() {
    mediaBrowser = new MediaBrowserCompat(getApplicationContext(),
            new ComponentName(getApplicationContext(), this.getClass()),
            new MediaBrowserCompat.ConnectionCallback() {
                @Override
                public void onConnected() {
                    super.onConnected();
                }

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

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

    mediaBrowser.connect();
}

@Override
public long getSupportedPrepareActions() {
    return PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID |
            PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH |
            PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH;
}

Auto capabilities work fine.

When i try to call this app on Auto from the emulator to play music it just does't do anything, it does not say errors or other stuff, it just closes google speak and then returns to the normal display. The method onPlayFromSearch is never called and it should be the one Auto would call if a voice command is sent.

Can someone help me figure out what i'm doing wrong? Google doc is pretty useless this way, Google UAP doesen't look to have this capability like the old version but looking at the old UAP version i cannot figure out what I'm doing wrong.

PS. The app is not published yet with this functionality

Thanks in advance.

e_ori
  • 845
  • 1
  • 11
  • 29

1 Answers1

15

To clear the review process, you’ll only need to get “Play X” (while the app is running in the foreground) working. After adding the intent filter, and if the app handles the search query while its running, I’d kick off another app review.

Otherwise, I believe it’s more of a Google Assistant feature that handles “Play X on Y” when the app is not in the foreground. I don’t have all the details on this, but the assistant may be querying their servers for the app name and package. If it isn’t published yet, it may not work locally.

EDIT

The best way to test your intent filter to clear the app review is to call the intent from adb on the mobile device with:

adb shell am start -a android.media.action.MEDIA_PLAY_FROM_SEARCH

If your app appears in the following media list drawer, the intent filter is setup correctly. You should then see the onPlayFromSearch "Test" log fire when "Play music" is sent while the app is running on Android Auto via the Desktop Head Unit.

salminnella
  • 744
  • 2
  • 6
  • 17
  • 1
    I tried adding the intent filter but Google Assistant always opens another app like Youtube Music or just Youtube, never my app. How can I test it? May it change if it's an APK on debug or release? @salminnella – e_ori Dec 27 '18 at 09:28
  • 1
    I added an adb command to help with testing. After the app is published, it will take some time (maybe a couple of days or more) for the app to be tagged and indexed for Google Assistant to run "play music on X app." Running in the debug or release variant won't have any affect locally as the Assistant is its own beast we don't have any control over. Its hard to find any real evidence, but there are similar issues on the Auto User Community forum or Google's issue tracker though. – salminnella Dec 28 '18 at 20:07
  • 2
    Thank you both for this question and answer. It amazes me at how poor google's developer documentation for Android Auto is, and how secretive their app review process is & what exactly is needed to pass.... and how it takes time before Google Assistant knows the app name and to marshall "play X on app Y" requests to your app. Since doing this, I seem to at least get my app to not be rejected for not supporting voice commands. I say seem because I've seen it happen where the app doesn't get rejected today but tomorrow it is submitted with no changes and fails. – Thomas Carlisle May 02 '19 at 18:43
  • @salminnella i facing similaire where the assistant not recognising my app the adb commande show my app. i'm not trying to supporting Android auto for now i just need to start song form the assistant. I did register ACTION_PLAY_FROM_SEARCH and implemented the onPlayFromSearch() but no luck. my app had been in the store for 3days. So you have any idea what the problem could be? plz share https://stackoverflow.com/questions/62771616/android-assistant-mediabrowserservice-voice-command-play-x-on-appname – Salah Hammouda Jul 15 '20 at 09:06
  • 4
    Agreed with @ThomasCarlisle. google's android auto docs and guidelines are very unclear and unproductive to work on. Garbage – RamPrasadBismil Oct 29 '20 at 19:48
  • 5
    The thing that got me is with Android 12 you need to declare activities as exported true/false. The activity that had my MEDIA_PLAY_FROM_SEARCH intent filter was set to exported=false, causing the voice search to fail. Once I changed exported=true, Google approved and all was well again. – codeman Jun 13 '22 at 14:28