@@ -74,10 +74,11 @@ public class Capture extends CordovaPlugin {
7474 private static final String LOG_TAG = "Capture" ;
7575
7676 private static final int CAPTURE_INTERNAL_ERR = 0 ;
77- // private static final int CAPTURE_APPLICATION_BUSY = 1;
77+ // private static final int CAPTURE_APPLICATION_BUSY = 1;
7878// private static final int CAPTURE_INVALID_ARGUMENT = 2;
7979 private static final int CAPTURE_NO_MEDIA_FILES = 3 ;
8080 private static final int CAPTURE_PERMISSION_DENIED = 4 ;
81+ private static final int CAPTURE_NOT_SUPPORTED = 20 ;
8182
8283 private boolean cameraPermissionInManifest ; // Whether or not the CAMERA permission is declared in AndroidManifest.xml
8384
@@ -229,13 +230,17 @@ private JSONObject getAudioVideoData(String filePath, JSONObject obj, boolean vi
229230 * Sets up an intent to capture audio. Result handled by onActivityResult()
230231 */
231232 private void captureAudio (Request req ) {
232- if (!PermissionHelper .hasPermission (this , Manifest .permission .READ_EXTERNAL_STORAGE )) {
233- PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .READ_EXTERNAL_STORAGE );
234- } else {
235- Intent intent = new Intent (android .provider .MediaStore .Audio .Media .RECORD_SOUND_ACTION );
233+ if (!PermissionHelper .hasPermission (this , Manifest .permission .READ_EXTERNAL_STORAGE )) {
234+ PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .READ_EXTERNAL_STORAGE );
235+ } else {
236+ try {
237+ Intent intent = new Intent (android .provider .MediaStore .Audio .Media .RECORD_SOUND_ACTION );
236238
237- this .cordova .startActivityForResult ((CordovaPlugin ) this , intent , req .requestCode );
238- }
239+ this .cordova .startActivityForResult ((CordovaPlugin ) this , intent , req .requestCode );
240+ } catch (ActivityNotFoundException ex ) {
241+ pendingRequests .resolveWithFailure (req , createErrorObject (CAPTURE_NOT_SUPPORTED , "No Activity found to handle Audio Capture." ));
242+ }
243+ }
239244 }
240245
241246 private String getTempDirectoryPath () {
@@ -254,16 +259,16 @@ private String getTempDirectoryPath() {
254259 */
255260 private void captureImage (Request req ) {
256261 boolean needExternalStoragePermission =
257- !PermissionHelper .hasPermission (this , Manifest .permission .READ_EXTERNAL_STORAGE );
262+ !PermissionHelper .hasPermission (this , Manifest .permission .WRITE_EXTERNAL_STORAGE );
258263
259264 boolean needCameraPermission = cameraPermissionInManifest &&
260- !PermissionHelper .hasPermission (this , Manifest .permission .CAMERA );
265+ !PermissionHelper .hasPermission (this , Manifest .permission .CAMERA );
261266
262267 if (needExternalStoragePermission || needCameraPermission ) {
263268 if (needExternalStoragePermission && needCameraPermission ) {
264- PermissionHelper .requestPermissions (this , req .requestCode , new String []{Manifest .permission .READ_EXTERNAL_STORAGE , Manifest .permission .CAMERA });
269+ PermissionHelper .requestPermissions (this , req .requestCode , new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE , Manifest .permission .CAMERA });
265270 } else if (needExternalStoragePermission ) {
266- PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .READ_EXTERNAL_STORAGE );
271+ PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .WRITE_EXTERNAL_STORAGE );
267272 } else {
268273 PermissionHelper .requestPermission (this , req .requestCode , Manifest .permission .CAMERA );
269274 }
@@ -517,11 +522,11 @@ private JSONObject createErrorObject(int code, String message) {
517522 */
518523 private Cursor queryImgDB (Uri contentStore ) {
519524 return this .cordova .getActivity ().getContentResolver ().query (
520- contentStore ,
521- new String [] { MediaStore .Images .Media ._ID },
522- null ,
523- null ,
524- null );
525+ contentStore ,
526+ new String [] { MediaStore .Images .Media ._ID },
527+ null ,
528+ null ,
529+ null );
525530 }
526531
527532 /**
0 commit comments