我正在测试我的应用程序的可访问性。如果用户在中间关闭辅助功能,则应用程序会崩溃,原因是服务未注册:android.speech.tts.TextToSpeech。我在 onDetachedFromWindow 方法中调用了 setJavaScriptEnabled(false) 但没有用。仍然有错误。
我没有在 webview 中使用应用程序上下文,因为 webview 正在使用 xml 进行初始化。
java.lang.IllegalArgumentException: Service not registered: android.speech.tts.TextToSpeech$Connection@49df6be0
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:940)
at android.app.ContextImpl.unbindService(ContextImpl.java:1983)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:541)
at android.speech.tts.TextToSpeech$Connection.disconnect(TextToSpeech.java:1575)
at android.speech.tts.TextToSpeech$1.run(TextToSpeech.java:732)
at android.speech.tts.TextToSpeech$1.run(TextToSpeech.java:727)
at android.speech.tts.TextToSpeech$Connection.runAction(TextToSpeech.java:1595)
at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:629)
at android.speech.tts.TextToSpeech.runActionNoReconnect(TextToSpeech.java:615)
at android.speech.tts.TextToSpeech.shutdown(TextToSpeech.java:727)
at com.android.org.chromium.content.browser.accessibility.AccessibilityInjector$TextToSpeechWrapper.shutdownInternal(AccessibilityInjector.java:462)
at com.android.org.chromium.content.browser.accessibility.AccessibilityInjector.removeAccessibilityApis(AccessibilityInjector.java:296)
at com.android.org.chromium.content.browser.accessibility.JellyBeanAccessibilityInjector.removeAccessibilityApis(JellyBeanAccessibilityInjector.java:97)
at com.android.org.chromium.content.browser.accessibility.AccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary(AccessibilityInjector.java:162)
at com.android.org.chromium.content.browser.ContentViewCore.setInjectedAccessibility(ContentViewCore.java:2884)
at com.android.org.chromium.content.browser.ContentViewCore.setAccessibilityState(ContentViewCore.java:2875)
at com.android.org.chromium.content.browser.ContentViewCore$16.onChange(ContentViewCore.java:2839)
at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:180)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
最佳答案
终于解决了。我必须从 xml 文件中移动所有 webview 并动态添加它们并传递应用程序上下文。
WebView webView = new WebView(getApplicationContext());
关于android - 服务未注册 : android. speech.tts.TextToSpeech,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27740935/