Skip to content

Commit f69ba2a

Browse files
authored
GH-102 Catch ActivityNotFoundException (#104)
1 parent 3755f9f commit f69ba2a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/android/Capture.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one
2727
import java.lang.reflect.Method;
2828
import java.util.Arrays;
2929

30+
import android.content.ActivityNotFoundException;
3031
import android.os.Build;
3132
import android.os.Bundle;
3233

@@ -75,6 +76,7 @@ public class Capture extends CordovaPlugin {
7576
// private static final int CAPTURE_INVALID_ARGUMENT = 2;
7677
private static final int CAPTURE_NO_MEDIA_FILES = 3;
7778
private static final int CAPTURE_PERMISSION_DENIED = 4;
79+
private static final int CAPTURE_NOT_SUPPORTED = 20;
7880

7981
private boolean cameraPermissionInManifest; // Whether or not the CAMERA permission is declared in AndroidManifest.xml
8082

@@ -229,9 +231,13 @@ private void captureAudio(Request req) {
229231
if (!PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
230232
PermissionHelper.requestPermission(this, req.requestCode, Manifest.permission.READ_EXTERNAL_STORAGE);
231233
} else {
232-
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
234+
try {
235+
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
233236

234-
this.cordova.startActivityForResult((CordovaPlugin) this, intent, req.requestCode);
237+
this.cordova.startActivityForResult((CordovaPlugin) this, intent, req.requestCode);
238+
} catch (ActivityNotFoundException ex) {
239+
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NOT_SUPPORTED, "No Activity found to handle Audio Capture."));
240+
}
235241
}
236242
}
237243

0 commit comments

Comments
 (0)