]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Catch exceptions when setting TTS language.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Wed, 30 Mar 2016 19:34:22 +0000 (21:34 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Wed, 30 Mar 2016 19:34:22 +0000 (21:34 +0200)
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.

res/values/strings.xml
src/com/hughes/android/dictionary/DictionaryActivity.java

index a1bc4df6099419c469006553f1ce2537dd4c741e..38824a87a64b7172ea9147e121ec03c51018b6a2 100644 (file)
@@ -48,6 +48,7 @@
     <string name="nextWord">Next word</string>
     <string name="previousWord">Previous word</string>
     <string name="randomWord">Random word</string>
+    <string name="TTSbroken">TTS is broken on this device</string>
 
     <!-- About dictionary. -->
     <string name="dictionaryPath">File: %s</string>
index 78c18231c935c7162a1a5461c5c1a482c6b10b72..67c1d834003bef2a626e24e840d45069f822f149 100644 (file)
@@ -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() {