From b3b110191068008c8b5180ff2d6d3af6373def9f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 30 Mar 2016 21:34:22 +0200 Subject: [PATCH] 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. --- res/values/strings.xml | 1 + src/com/hughes/android/dictionary/DictionaryActivity.java | 4 ++++ 2 files changed, 5 insertions(+) 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() { -- 2.43.0