Skip to content

Commit

Permalink
fix(android): handle some resolveWithFailure in AudioActivityResult
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Aug 7, 2023
1 parent 273f583 commit 0047839
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/android/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ else if (resultCode == Activity.RESULT_CANCELED) {
public void onAudioActivityResult(Request req, Intent intent) {
Uri srcContentUri = intent.getData();

if (srcContentUri == null) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
return;
}

// Get file name
String srcContentUriString = srcContentUri.toString();
String fileName = srcContentUriString.substring(srcContentUriString.lastIndexOf('/') + 1);
Expand All @@ -410,11 +415,12 @@ public void onAudioActivityResult(Request req, Intent intent) {
destFOS.write(buf, 0, length);
}
} else {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: failed to copy recording to application cache directory."));
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: failed to create new file to application cache directory."));
return;
}
} catch (IOException e) {
throw new RuntimeException(e);
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: failed to copy recording to application cache directory."));
return;
}

LOG.d(LOG_TAG, "Recording file path: " + destFile);
Expand All @@ -428,7 +434,8 @@ public void onAudioActivityResult(Request req, Intent intent) {
mediaFile.put("lastModifiedDate", tmpRootFile.lastModified());
mediaFile.put("size", tmpRootFile.length());
} catch (JSONException e) {
throw new RuntimeException(e);
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_INTERNAL_ERR, "Error: no mediaFile created from " + srcContentUri));
return;
}

req.results.put(mediaFile);
Expand Down

0 comments on commit 0047839

Please sign in to comment.