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 MediaBrowserServiceCompat
which 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.
If your Google Assistant doesn't work or respond to “Hey Google” on your Android device, make sure Google Assistant, Hey Google and Voice Match are turned on: On your Android phone or tablet, go to Assistant settings, or open the Google Assistant app. and say, “Assistant settings.”
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With