gpt4 book ai didi

android - 如何摆脱 Android 中的 'Service not registered: android.speech.SpeechRecognizer' 错误

转载 作者:行者123 更新时间:2023-12-05 00:05:48 26 4
gpt4 key购买 nike

我让我的用户使用 SpeechRecognizer,某些类型的手机和 Android 版本会收到一个错误,即“服务未注册:android.speech.SpeechRecognizer”。

if (speech != null) {
speech!!.stopListening()
speech!!.cancel()
speech!!.destroy() // PictureVoiceActivity.kt:489
}
//
viewPager.setCurrentItem(viewPager.currentItem + 1, true) speech!!.destroy() // PictureVoiceActivity.kt:360

错误日志:

Fatal Exception: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@2d1871c9
at android.app.LoadedApk.forgetServiceDispatcher + 1151(LoadedApk.java:1151)
at android.app.ContextImpl.unbindService + 2253(ContextImpl.java:2253)
at android.content.ContextWrapper.unbindService + 572(ContextWrapper.java:572)
at android.speech.SpeechRecognizer.destroy + 408(SpeechRecognizer.java:408)
at com.blarma.high5.aui.lesson.PictureVoiceActivity$ArrayFragment.onPause + 489(PictureVoiceActivity.kt:489)
at androidx.fragment.app.Fragment.performPause + 2787(Fragment.java:2787)
at androidx.fragment.app.FragmentManagerImpl.moveToState + 935(FragmentManagerImpl.java:935)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState + 1240(FragmentManagerImpl.java:1240)
at androidx.fragment.app.BackStackRecord.executeOps + 434(BackStackRecord.java:434)
at androidx.fragment.app.FragmentManagerImpl.executeOps + 2078(FragmentManagerImpl.java:2078)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether + 1868(FragmentManagerImpl.java:1868)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute + 1823(FragmentManagerImpl.java:1823)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction + 1698(FragmentManagerImpl.java:1698)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss + 299(BackStackRecord.java:299)
at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate + 256(FragmentStatePagerAdapter.java:256)
at androidx.viewpager.widget.ViewPager.populate + 1244(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal + 669(ViewPager.java:669)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal + 631(ViewPager.java:631)
at androidx.viewpager.widget.ViewPager.setCurrentItem + 623(ViewPager.java:623)
at com.blarma.high5.aui.lesson.PictureVoiceActivity$ArrayFragment$onCreateView$3.onClick + 360(PictureVoiceActivity.kt:360)
at android.view.View.performClick + 5246(View.java:5246)
at android.widget.TextView.performClick + 10565(TextView.java:10565)
at android.view.View$PerformClick.run + 21200(View.java:21200)
at android.os.Handler.handleCallback + 739(Handler.java:739)
at android.os.Handler.dispatchMessage + 95(Handler.java:95)
at android.os.Looper.loop + 145(Looper.java:145)
at android.app.ActivityThread.main + 6946(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke + 372(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1404(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main + 1199(ZygoteInit.java:1199)

最佳答案

将 SearchSupportFragment 类复制到您的项目中并修改 releaseRecognizer 方法。之后从这个类扩展你的 fragment 。

private void releaseRecognizer() {
try {
if (null != mSpeechRecognizer) {
mSearchBar.setSpeechRecognizer(null);
mSpeechRecognizer.destroy();
mSpeechRecognizer = null;
}
} catch (IllegalArgumentException e) { // fix Service not registered: android.speech.SpeechRecognizer$Connection
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
}

关于android - 如何摆脱 Android 中的 'Service not registered: android.speech.SpeechRecognizer' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57250491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com