From fa71909df5144171b52870bffee3bbcb8b9b0ef8 Mon Sep 17 00:00:00 2001 From: Olga Miller Date: Sat, 25 Feb 2023 13:02:15 +0100 Subject: [PATCH] Moved resolving and starting another activity to tryToStartActivityForResult-method and added Toast messages --- .../java/om/sstvencoder/MainActivity.java | 29 ++++++++++++------- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/om/sstvencoder/MainActivity.java b/app/src/main/java/om/sstvencoder/MainActivity.java index 7a49c5f..370020a 100644 --- a/app/src/main/java/om/sstvencoder/MainActivity.java +++ b/app/src/main/java/om/sstvencoder/MainActivity.java @@ -391,25 +391,34 @@ public class MainActivity extends AppCompatActivity { public void startEditTextActivity(@NonNull Label label) { Intent intent = new Intent(this, EditTextActivity.class); intent.putExtra(EditTextActivity.EXTRA, label); - startActivityForResult(intent, EditTextActivity.REQUEST_CODE); + tryToStartActivityForResult(intent, EditTextActivity.REQUEST_CODE); } private void dispatchTakePictureIntent() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - if (intent.resolveActivity(getPackageManager()) != null) { - Uri uri = Utility.createImageUri(this); - if (uri != null) { - mSettings.setImageUri(uri); - intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); - } + Uri uri = Utility.createImageUri(this); + if (uri != null) { + mSettings.setImageUri(uri); + intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + tryToStartActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } private void dispatchPickPictureIntent() { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - if (intent.resolveActivity(getPackageManager()) != null) - startActivityForResult(intent, REQUEST_PICK_IMAGE); + tryToStartActivityForResult(intent, REQUEST_PICK_IMAGE); + } + + private void tryToStartActivityForResult(Intent intent, int requestCode) { + if (intent.resolveActivity(getPackageManager()) == null) { + Toast.makeText(this, R.string.another_activity_resolve_err, Toast.LENGTH_LONG).show(); + return; + } + try { + startActivityForResult(intent, requestCode); + } catch (Exception ignore) { + Toast.makeText(this, R.string.another_activity_start_err, Toast.LENGTH_LONG).show(); + } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1108616..c79a4e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,6 +45,8 @@ Unsupported content. Previous image could not be loaded. Device has no camera. + Another activity could not be resolved. + Another activity could not be started. Send Email OK SSTV Encoder - Bug Report