This is an automated email from the ASF dual-hosted git repository.

jcesarmobile pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/cordova-plugin-media-capture.git


The following commit(s) were added to refs/heads/master by this push:
     new f69ba2a  GH-102 Catch ActivityNotFoundException (#104)
f69ba2a is described below

commit f69ba2a67417e51555eb5926851592ecf1b84601
Author: jcesarmobile <jcesarmob...@gmail.com>
AuthorDate: Sat Sep 22 02:07:06 2018 +0200

    GH-102 Catch ActivityNotFoundException (#104)
---
 src/android/Capture.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/android/Capture.java b/src/android/Capture.java
index 24578bc..33c3413 100644
--- a/src/android/Capture.java
+++ b/src/android/Capture.java
@@ -27,6 +27,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 
+import android.content.ActivityNotFoundException;
 import android.os.Build;
 import android.os.Bundle;
 
@@ -75,6 +76,7 @@ public class Capture extends CordovaPlugin {
 //    private static final int CAPTURE_INVALID_ARGUMENT = 2;
     private static final int CAPTURE_NO_MEDIA_FILES = 3;
     private static final int CAPTURE_PERMISSION_DENIED = 4;
+    private static final int CAPTURE_NOT_SUPPORTED = 20;
 
     private boolean cameraPermissionInManifest;     // Whether or not the 
CAMERA permission is declared in AndroidManifest.xml
 
@@ -229,9 +231,13 @@ public class Capture extends CordovaPlugin {
       if (!PermissionHelper.hasPermission(this, 
Manifest.permission.READ_EXTERNAL_STORAGE)) {
           PermissionHelper.requestPermission(this, req.requestCode, 
Manifest.permission.READ_EXTERNAL_STORAGE);
       } else {
-          Intent intent = new 
Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
+          try {
+              Intent intent = new 
Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
 
-          this.cordova.startActivityForResult((CordovaPlugin) this, intent, 
req.requestCode);
+              this.cordova.startActivityForResult((CordovaPlugin) this, 
intent, req.requestCode);
+          } catch (ActivityNotFoundException ex) {
+              pendingRequests.resolveWithFailure(req, 
createErrorObject(CAPTURE_NOT_SUPPORTED, "No Activity found to handle Audio 
Capture."));
+          }
       }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to