我为Android实现了一项TTS服务,该服务可以正常运行。我还可以通过Android设置应用的“文本转语音”部分管理其设置。
但是,在运行Android 8.1的Pixel平板电脑上,设置应用程序因我的TTS实施而崩溃,但以下情况除外:
2019-02-25 10:45:46.396 5816-5816/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.settings, PID: 5816
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1742)
at android.app.Activity.startActivityForResult(Activity.java:5168)
at android.app.Activity.startActivityFromFragment(Activity.java:5144)
at android.app.Activity$HostCallbacks.onStartActivityFromFragment(Activity.java:7690)
at android.app.Fragment.startActivity(Fragment.java:1075)
at android.app.Fragment.startActivity(Fragment.java:1054)
at com.android.settings.tts.TextToSpeechSettings.onGearClick(TextToSpeechSettings.java:780)
at com.android.settings.widget.GearPreference.onClick(GearPreference.java:71)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我找不到any docs of what setting implementation I am required to implement for the Service。有提示吗?
答案 0 :(得分:0)
我所缺少的是指向服务设置活动的元数据(在此处扩展了PreferenceActivity和EngineSettings的类):
在AndroidManifest.xml中:
<service
android:name=".MyTtsService"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.TTS_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.speech.tts" android:resource="@xml/tts_engine" />
</service>
还有tts_engine.xml:
<?xml version="1.0" encoding="utf-8"?>
<tts-engine xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.mytts.EngineSettings" />