From bef96cc9cd499ac7cb392842f8423f4b71c2e015 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Mon, 10 Sep 2018 20:58:34 +0200 Subject: [PATCH] Revert "Remove unneeded try catch in voice command funtionality (#899)" (#984) * Revert "Remove unneeded try catch in voice command funtionality (#899)" In some case the try catch is needed. See https://console.firebase.google.com/project/openhab-mobile/crashlytics/app/android:org.openhab.habdroid/issues/5b755c156007d59fcdf12bc8 (only visible to the openHAB staff). I updated the code to open the Google app in any app store. Some users might use YALP store or any other custom Play Store (or Amazon app store). For users without any additional app store the Play Store is opened. Signed-off-by: mueller-ma * Show toast if no app store is installed Signed-off-by: mueller-ma --- .../openhab/habdroid/ui/OpenHABMainActivity.java | 14 +++++++++++++- mobile/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java index 201de691bf..c4ba053af6 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java +++ b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java @@ -12,6 +12,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.PendingIntent; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -59,6 +60,7 @@ import android.view.ViewStub; import android.view.WindowManager; import android.widget.ProgressBar; +import android.widget.Toast; import org.json.JSONArray; import org.json.JSONException; @@ -1004,7 +1006,17 @@ private void launchVoiceRecognition() { speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); speechIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, openhabPendingIntent); - startActivity(speechIntent); + try { + startActivity(speechIntent); + } catch (ActivityNotFoundException speechRecognizerNotFoundException) { + try { + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("market://details?id=com.google.android.googlequicksearchbox"))); + } catch (ActivityNotFoundException appStoreNotFoundException) { + Toast.makeText(this, R.string.error_no_app_store_found, + Toast.LENGTH_LONG).show(); + } + } } public void showRefreshHintSnackbarIfNeeded() { diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 45a4ff8e51..da2c1f821b 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -103,6 +103,7 @@ Network authentication is required (HTTP response code 511) Error while fetching openHAB server information Your openHAB server is offline while the cloud instance is running + No app store found to install voice recognizer app Write NFC tag Used libraries Touch the tag and keep it close until the confirmation message appear