Skip to content

Commit

Permalink
GH-102 Catch ActivityNotFoundException (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Sep 22, 2018
1 parent 3755f9f commit f69ba2a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/android/Capture.java
Expand Up @@ -27,6 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.lang.reflect.Method;
import java.util.Arrays;

import android.content.ActivityNotFoundException;
import android.os.Build;
import android.os.Bundle;

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -229,9 +231,13 @@ private void captureAudio(Request req) {
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."));
}
}
}

Expand Down

0 comments on commit f69ba2a

Please sign in to comment.