デバイスで TTS エンジンの可用性を確認するためのコードがあります。ステートメント tts.getEngines().size() < 1 は API 14 からのみ実行されるため、API 8 からでも同じ機能をチェックする方法 (メソッド) があるかどうかを知る必要があります。
前もって感謝します
コード:
private void checkTTSAvailability() {
tts = new TextToSpeech(this, this);
ttsPresent=true;
**if (tts.getEngines().size() < 1) {**
PackageManager pm = getPackageManager();
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
ResolveInfo resolveInfo = pm.resolveActivity(installIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo == null) {
Log.i("DragDrop", "No voice support on your phone");
Dialog d = new Dialog(this);
d.setTitle("Alert ");
TextView tv = new TextView(this);
tv.setText("No voice support on your phone");
d.setContentView(tv);
d.show();
ttsPresent=false;
// Not able to find the activity which should be started for
// this intent
} else {
Dialog d = new Dialog(this);
d.setTitle("Alert ");
TextView tv = new TextView(this);
tv.setText("Installing");
d.setContentView(tv);
d.show();
Log.i("DragDrop", "Installing");
startActivity(installIntent);
}
}
}