Skip to content

Commit

Permalink
Revert "Remove unneeded try catch in voice command funtionality (#899)…
Browse files Browse the repository at this point in the history
…" (#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 <[email protected]>

* Show toast if no app store is installed

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Sep 10, 2018
1 parent 592f96d commit bef96cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<string name="error_http_code_511">Network authentication is required (HTTP response code 511)</string>
<string name="error_about_no_conn">Error while fetching openHAB server information</string>
<string name="error_openhab_offline">Your openHAB server is offline while the cloud instance is running</string>
<string name="error_no_app_store_found">No app store found to install voice recognizer app</string>
<string name="title_activity_openhabwritetag">Write NFC tag</string>
<string name="title_activity_libraries">Used libraries</string>
<string name="info_write_tag">Touch the tag and keep it close until the confirmation message appear</string>
Expand Down

0 comments on commit bef96cc

Please sign in to comment.