Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): handle cancelled media capture intent (#291) #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/android/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ private void captureVideo(Request req) {
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
final Request req = pendingRequests.get(requestCode);

// Result received okay
if (resultCode == Activity.RESULT_OK) {
// Result received okay or the capture image intent has been cancelled
if (resultCode == Activity.RESULT_OK || (req.action == CAPTURE_IMAGE && intent == null)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why specifically CAPTURE_IMAGE? It may be the case for audio and video capture too?

Runnable processActivityResult = new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -419,6 +419,17 @@ public void onImageActivityResult(Request req) {
return;
}

long size = 0;
try {
size = mediaFile.getLong("size");
} catch (JSONException e) {
// noop
}
if (size == 0) {
pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: file is empty"));
return;
}

req.results.put(mediaFile);

checkForDuplicateImage();
Expand Down