erisu commented on code in PR #308: URL: https://github.com/apache/cordova-plugin-media-capture/pull/308#discussion_r1898218340
########## src/android/Capture.java: ########## @@ -394,8 +394,46 @@ else if (resultCode == Activity.RESULT_CANCELED) { } } + public void onAudioActivityResult(Request req, Intent intent) { + Uri uri = intent.getData(); + + InputStream input = null; + OutputStream output = null; + try { + if (uri == null) { + throw new IOException("Unable to open input audio"); + } + + input = this.cordova.getActivity().getContentResolver().openInputStream(uri); + + if (input == null) { + throw new IOException("Unable to open input audio"); + } + + output = new FileOutputStream(this.audioAbsolutePath); + + byte[] buffer = new byte[getPageSize()]; + int bytesRead; + while ((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + } + catch (FileNotFoundException e) { + pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to read input audio: File not found")); + } + catch (IOException e) { + pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to read input audio")); + } + finally { + try { + if (output != null) output.close(); + if (input != null) input.close(); + } + catch (IOException ex) { Review Comment: ```suggestion } catch (IOException ex) { ``` ########## src/android/Capture.java: ########## @@ -288,11 +252,42 @@ private void captureAudio(Request req) { } } + /** + * Checks for and requests the camera permission if necessary. + * + * Returns a boolean which if true, signals that the permission has been granted, or that the + * permission isn't necessary and that the action may continue as normal. + * + * If the response is false, then the action should stop performing, as a permission prompt + * will be presented to the user. The action based on the request's requestCode will be invoked + * later. + * + * @param req + * @return + */ + private boolean requestCameraPermission(Request req) { + boolean cameraPermissionGranted = true; // We will default to true, but if the manifest + // declares the permission, then we need to check + // for the grant Review Comment: ```suggestion // Defaults to true. If the manifest declares permission then check for the grant boolean cameraPermissionGranted = true; ``` Could consolidate lines for comment. ########## src/android/Capture.java: ########## @@ -394,8 +394,46 @@ else if (resultCode == Activity.RESULT_CANCELED) { } } + public void onAudioActivityResult(Request req, Intent intent) { + Uri uri = intent.getData(); + + InputStream input = null; + OutputStream output = null; + try { + if (uri == null) { + throw new IOException("Unable to open input audio"); + } + + input = this.cordova.getActivity().getContentResolver().openInputStream(uri); + + if (input == null) { + throw new IOException("Unable to open input audio"); + } + + output = new FileOutputStream(this.audioAbsolutePath); + + byte[] buffer = new byte[getPageSize()]; + int bytesRead; + while ((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + } + catch (FileNotFoundException e) { + pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: Unable to read input audio: File not found")); + } + catch (IOException e) { Review Comment: ```suggestion } catch (IOException e) { ``` ########## src/android/Capture.java: ########## @@ -394,8 +394,46 @@ else if (resultCode == Activity.RESULT_CANCELED) { } } + public void onAudioActivityResult(Request req, Intent intent) { + Uri uri = intent.getData(); + + InputStream input = null; + OutputStream output = null; + try { + if (uri == null) { + throw new IOException("Unable to open input audio"); + } + + input = this.cordova.getActivity().getContentResolver().openInputStream(uri); + + if (input == null) { + throw new IOException("Unable to open input audio"); + } + + output = new FileOutputStream(this.audioAbsolutePath); + + byte[] buffer = new byte[getPageSize()]; + int bytesRead; + while ((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + } + catch (FileNotFoundException e) { Review Comment: ```suggestion } catch (FileNotFoundException e) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org