@@ -27,6 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one
27
27
import java .lang .reflect .Method ;
28
28
import java .util .Arrays ;
29
29
30
+ import android .content .ActivityNotFoundException ;
30
31
import android .os .Build ;
31
32
import android .os .Bundle ;
32
33
@@ -75,6 +76,7 @@ public class Capture extends CordovaPlugin {
75
76
// private static final int CAPTURE_INVALID_ARGUMENT = 2;
76
77
private static final int CAPTURE_NO_MEDIA_FILES = 3 ;
77
78
private static final int CAPTURE_PERMISSION_DENIED = 4 ;
79
+ private static final int CAPTURE_NOT_SUPPORTED = 20 ;
78
80
79
81
private boolean cameraPermissionInManifest ; // Whether or not the CAMERA permission is declared in AndroidManifest.xml
80
82
@@ -229,9 +231,13 @@ private void captureAudio(Request req) {
229
231
if (!PermissionHelper .hasPermission (this , Manifest .permission .READ_EXTERNAL_STORAGE )) {
230
232
PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .READ_EXTERNAL_STORAGE );
231
233
} 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 );
233
236
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
+ }
235
241
}
236
242
}
237
243
0 commit comments