android.speech.RecognitionService SecurityException 与一些 3rd 方语音识别器

Fis*_*her 5 android speech-recognition securityexception device sfspeechrecognizer

我们创建了一个使用 Google 语音识别器的 Android 应用程序,我们首先在程序中选择使用 Google 语音识别器。大多数设备工作正常,只有少数设备(MEIZU_M5、U78-E、Apollo Lite 等)报告以下异常。好像和联发科的语音指令有些冲突?我们发现其他一些联发科的设备工作正常。这很混乱。

java.lang.SecurityException: Not allowed to bind to service Intent { act=android.speech.RecognitionService cmp=com.mediatek.voicecommand/.service.VoiceWakeupRecognitionService }
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1421)
at android.app.ContextImpl.bindService(ContextImpl.java:1385)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at android.speech.SpeechRecognizer.startListening(SpeechRecognizer.java:287)
Run Code Online (Sandbox Code Playgroud)

为了跟踪代码,源代码只显示到 ContextWrapper.java。如何让它显示到 ContextImpl.java:1421?

通过 firebase 日志,我们发现它发生在许多 3rd 方语音识别器上:

com.mediatek.voicecommand
com.htc.android.voicedictation
com.vlingo.midas
com.iflytek.speechcloud
com.iflytek.speechsuite
...
Run Code Online (Sandbox Code Playgroud)

我们还测试了其他一些运行良好的第 3 方语音识别器。那些导致异常的语音识别器是否仅用于系统语音命令而应用程序无法访问?

欢迎任何想法或经验。

Fis*_*her 2

最后,我们从Android开发者 服务概述中的一些信息中找到了根本原因:

但是,您可以在清单文件中将该服务声明为私有,并阻止其他应用程序的访问。

这些 3rd-party SpeechRecognizer 服务是私有的,不能被其他应用程序调用。因此,我们只是尝试捕获此异常并通知用户安装 Google 应用程序(语音输入)。或者您可以通过跳过这些意外的 SpeechRecognizer 来排除它们。