Skip to content

Commit 7f69acd

Browse files
npomfretZack Story
authored andcommitted
when saving images, only invoke the media scanner if the user is saving to the camera roll. (react-native-camera#716)
1 parent acc60d3 commit 7f69acd

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private synchronized void processImage(MutableImage mutableImage, ReadableMap op
605605

606606
addToMediaStore(cameraRollFile.getAbsolutePath());
607607

608-
resolve(cameraRollFile, promise);
608+
resolveImage(cameraRollFile, promise, true);
609609

610610
break;
611611
}
@@ -623,7 +623,7 @@ private synchronized void processImage(MutableImage mutableImage, ReadableMap op
623623
return;
624624
}
625625

626-
resolve(pictureFile, promise);
626+
resolveImage(pictureFile, promise, false);
627627

628628
break;
629629
}
@@ -641,7 +641,7 @@ private synchronized void processImage(MutableImage mutableImage, ReadableMap op
641641
return;
642642
}
643643

644-
resolve(tempFile, promise);
644+
resolveImage(tempFile, promise, false);
645645

646646
break;
647647
}
@@ -764,27 +764,31 @@ public void onHostDestroy() {
764764
// ... do nothing
765765
}
766766

767-
private void resolve(final File imageFile, final Promise promise) {
767+
private void resolveImage(final File imageFile, final Promise promise, boolean addToMediaStore) {
768768
final WritableMap response = new WritableNativeMap();
769769
response.putString("path", Uri.fromFile(imageFile).toString());
770770

771-
// borrowed from react-native CameraRollManager, it finds and returns the 'internal'
772-
// representation of the image uri that was just saved.
773-
// e.g. content://media/external/images/media/123
774-
MediaScannerConnection.scanFile(
775-
_reactContext,
776-
new String[]{imageFile.getAbsolutePath()},
777-
null,
778-
new MediaScannerConnection.OnScanCompletedListener() {
779-
@Override
780-
public void onScanCompleted(String path, Uri uri) {
781-
if (uri != null) {
782-
response.putString("mediaUri", uri.toString());
771+
if(addToMediaStore) {
772+
// borrowed from react-native CameraRollManager, it finds and returns the 'internal'
773+
// representation of the image uri that was just saved.
774+
// e.g. content://media/external/images/media/123
775+
MediaScannerConnection.scanFile(
776+
_reactContext,
777+
new String[]{imageFile.getAbsolutePath()},
778+
null,
779+
new MediaScannerConnection.OnScanCompletedListener() {
780+
@Override
781+
public void onScanCompleted(String path, Uri uri) {
782+
if (uri != null) {
783+
response.putString("mediaUri", uri.toString());
784+
}
785+
786+
promise.resolve(response);
783787
}
784-
785-
promise.resolve(response);
786-
}
787-
});
788+
});
789+
} else {
790+
promise.resolve(response);
791+
}
788792
}
789793

790794
}

0 commit comments

Comments
 (0)