简体   繁体   English

无法在Android Auto Media App上运行语音命令

[英]Can't get voice commands on Android Auto Media App work

I have an Android App with working Auto capabilities which has been rejected from the store because: 我有一个Android应用程序具有工作自动功能,已被商店拒绝,因为:

"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"." “您的应用程序不支持所有必需的语音命令。例如,您的应用程序不包含用于操作的Intent过滤器”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. 所以我看起来至少让应用程序响应“在X应用程序上播放音乐”,但通过查看文档,我无法让它工作。 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: 它会触发以这种方式初始化的MediaBrowserServiceCompat :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. 永远不会调用onPlayFromSearch方法,如果发送语音命令,它应该是Auto会调用的方法。

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. 谷歌文档这种方式很无用,谷歌UAP看起来不像老版本那样具有这种功能,但是看看旧的UAP版本,我无法弄清楚我做错了什么。

PS. PS。 The app is not published yet with this functionality 该应用尚未使用此功能发布

Thanks in advance. 提前致谢。

To clear the review process, you'll only need to get “Play X” (while the app is running in the foreground) working. 要清除审核流程,您只需要“Play X”(当应用程序在前台运行时)工作。 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. 否则,我认为当应用程序不在前台时,它更像是一个处理“在Y上播放X”的Google智能助理功能。 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调用intent:

adb shell am start -a android.media.action.MEDIA_PLAY_FROM_SEARCH 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. 当应用程序通过桌面主机单元在Android Auto上运行时,您应该在发送“播放音乐”时看到onPlayFromSearch“测试”日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM