From: Reimar Döffinger Date: Wed, 30 Mar 2016 19:34:22 +0000 (+0200) Subject: Catch exceptions when setting TTS language. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=b3b110191068008c8b5180ff2d6d3af6373def9f Catch exceptions when setting TTS language. On some Galaxy S6, Android 6.0 it results in a java.lang.IllegalArgumentException: Invalid int: "OS" This is almost certainly an Android bug, but show a message instead of crashing. --- diff --git a/res/values/strings.xml b/res/values/strings.xml index a1bc4df..38824a8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -48,6 +48,7 @@ Next word Previous word Random word + TTS is broken on this device File: %s diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 78c1823..67c1d83 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -668,11 +668,15 @@ public class DictionaryActivity extends ActionBarActivity { } final Locale locale = new Locale(dictionary.indices.get(i).sortLanguage.getIsoCode()); Log.d(LOG, "Setting TTS locale to: " + locale); + try { final int ttsResult = textToSpeech.setLanguage(locale); if (ttsResult != TextToSpeech.LANG_AVAILABLE && ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) { Log.e(LOG, "TTS not available in this language: ttsResult=" + ttsResult); } + } catch (Exception e) { + Toast.makeText(this, getString(R.string.TTSbroken), Toast.LENGTH_LONG).show(); + } } void onLanguageButtonClick() {