diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
index 46b0f4ab5c2a..2daf9e68f650 100755
--- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java
@@ -795,6 +795,10 @@ public void onMediaCapturePathReady(String mediaCapturePath) {
mMediaCapturePath = mediaCapturePath;
}
+ @Override public void onCameraError(String errorMessage) {
+ ToastUtils.showToast(this, errorMessage, LONG);
+ }
+
private void showMediaToastError(@StringRes int message, @Nullable String messageDetail) {
if (isFinishing()) {
return;
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt
index 4f989fa1160a..4732b8ddac8e 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt
@@ -47,6 +47,7 @@ import org.wordpress.android.ui.posts.editor.ImageEditorTracker
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.MEDIA
+import org.wordpress.android.util.ToastUtils
import org.wordpress.android.util.WPMediaUtils
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat
@@ -316,7 +317,23 @@ class MediaPickerActivity : LocaleAwareActivity(), MediaPickerListener {
startActivityForResult(buildIntent(this, action.mediaPickerSetup, site, localPostId), PHOTO_PICKER)
}
OpenCameraForPhotos -> {
- WPMediaUtils.launchCamera(this, BuildConfig.APPLICATION_ID) { mediaCapturePath = it }
+ WPMediaUtils.launchCamera(
+ this,
+ BuildConfig.APPLICATION_ID,
+ object : WPMediaUtils.LaunchCameraCallback {
+ override fun onMediaCapturePathReady(mediaCapturePath: String?) {
+ this@MediaPickerActivity.mediaCapturePath = mediaCapturePath
+ }
+
+ override fun onCameraError(errorMessage: String?) {
+ ToastUtils.showToast(
+ this@MediaPickerActivity,
+ errorMessage,
+ ToastUtils.Duration.SHORT
+ )
+ }
+ }
+ )
}
}
}
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java
index ecb826c1a67f..db908316a905 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerActivity.java
@@ -34,6 +34,7 @@
import org.wordpress.android.util.ListUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.WPMediaUtils;
+import org.wordpress.android.util.WPMediaUtils.LaunchCameraCallback;
import java.io.File;
import java.util.ArrayList;
@@ -230,7 +231,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
private void launchCameraForImage() {
WPMediaUtils.launchCamera(this, BuildConfig.APPLICATION_ID,
- mediaCapturePath -> mMediaCapturePath = mediaCapturePath);
+ new LaunchCameraCallback() {
+ @Override
+ public void onMediaCapturePathReady(String mediaCapturePath) {
+ // Handle the path for the captured media
+ mMediaCapturePath = mediaCapturePath;
+ }
+
+ @Override
+ public void onCameraError(String errorMessage) {
+ // Handle the error, e.g., display an error message to the user
+ ToastUtils.showToast(PhotoPickerActivity.this, errorMessage);
+ }
+ }
+ );
}
private void launchPictureLibrary(boolean multiSelect) {
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt
index 0a0f9691533a..24bb39d941be 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt
@@ -2648,9 +2648,23 @@ class EditPostActivity : LocaleAwareActivity(), EditorFragmentActivity, EditorIm
}
private fun launchCamera() {
- WPMediaUtils.launchCamera(this, BuildConfig.APPLICATION_ID) { mediaCapturePath ->
- this.mediaCapturePath = mediaCapturePath
- }
+ WPMediaUtils.launchCamera(
+ this,
+ BuildConfig.APPLICATION_ID,
+ object : WPMediaUtils.LaunchCameraCallback {
+ override fun onMediaCapturePathReady(mediaCapturePath: String?) {
+ this@EditPostActivity.mediaCapturePath = mediaCapturePath
+ }
+
+ override fun onCameraError(errorMessage: String?) {
+ ToastUtils.showToast(
+ this@EditPostActivity,
+ errorMessage,
+ ToastUtils.Duration.SHORT
+ )
+ }
+ }
+ )
}
private fun setPostContentFromShareAction() {
diff --git a/WordPress/src/main/java/org/wordpress/android/util/WPMediaUtils.java b/WordPress/src/main/java/org/wordpress/android/util/WPMediaUtils.java
index c66d711b0762..24e47daeb759 100644
--- a/WordPress/src/main/java/org/wordpress/android/util/WPMediaUtils.java
+++ b/WordPress/src/main/java/org/wordpress/android/util/WPMediaUtils.java
@@ -48,6 +48,8 @@
public class WPMediaUtils {
public interface LaunchCameraCallback {
void onMediaCapturePathReady(String mediaCapturePath);
+
+ void onCameraError(String errorMessage);
}
// 3000px is the utmost max resolution you can set in the picker but 2000px is the default max for optimized images.
@@ -300,7 +302,13 @@ private static Intent prepareGalleryIntent(String title) {
public static void launchCamera(Activity activity, String applicationId, LaunchCameraCallback callback) {
Intent intent = prepareLaunchCamera(activity, applicationId, callback);
if (intent != null) {
- activity.startActivityForResult(intent, RequestCodes.TAKE_PHOTO);
+ // Check if there is an app that can handle the camera intent
+ if (intent.resolveActivity(activity.getPackageManager()) != null) {
+ activity.startActivityForResult(intent, RequestCodes.TAKE_PHOTO);
+ } else {
+ // Handle the case where no camera app is available
+ callback.onCameraError(activity.getString(R.string.error_no_camera_available));
+ }
}
}
diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml
index da8ea2487f2b..a102e246e78f 100644
--- a/WordPress/src/main/res/values/strings.xml
+++ b/WordPress/src/main/res/values/strings.xml
@@ -2084,6 +2084,7 @@
Unable to load this page right now.
Check your network connection and try again.
Couldn\'t update site title. Check your network connection and try again.
+ No camera app available.
Could not find the post on the server