Skip to content

Commit

Permalink
feat(camera): Support for Samsung Gallery app on pickImages (#706)
Browse files Browse the repository at this point in the history
Co-authored-by: Carl Poole <[email protected]>
Co-authored-by: jcesarmobile <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2022
1 parent 3d63d09 commit fd059fc
Showing 1 changed file with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Base64;
import androidx.activity.result.ActivityResult;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void getPhoto(PluginCall call) {
@PluginMethod
public void pickImages(PluginCall call) {
settings = getSettings(call);
openPhotos(call, true);
openPhotos(call, true, false);
}

private void doShow(PluginCall call) {
Expand Down Expand Up @@ -192,17 +193,20 @@ private boolean checkPhotosPermissions(PluginCall call) {
*/
@PermissionCallback
private void cameraPermissionsCallback(PluginCall call) {
if (settings.getSource() == CameraSource.CAMERA && getPermissionState(CAMERA) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA).toString());
call.reject(PERMISSION_DENIED_ERROR_CAMERA);
return;
} else if (settings.getSource() == CameraSource.PHOTOS && getPermissionState(PHOTOS) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied photos permission: " + getPermissionState(PHOTOS).toString());
call.reject(PERMISSION_DENIED_ERROR_PHOTOS);
return;
if (call.getMethodName().equals("pickImages")) {
openPhotos(call, true, true);
} else {
if (settings.getSource() == CameraSource.CAMERA && getPermissionState(CAMERA) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA).toString());
call.reject(PERMISSION_DENIED_ERROR_CAMERA);
return;
} else if (settings.getSource() == CameraSource.PHOTOS && getPermissionState(PHOTOS) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied photos permission: " + getPermissionState(PHOTOS).toString());
call.reject(PERMISSION_DENIED_ERROR_PHOTOS);
return;
}
doShow(call);
}

doShow(call);
}

private CameraSettings getSettings(PluginCall call) {
Expand Down Expand Up @@ -260,16 +264,18 @@ public void openCamera(final PluginCall call) {
}

public void openPhotos(final PluginCall call) {
openPhotos(call, false);
openPhotos(call, false, false);
}

private void openPhotos(final PluginCall call, boolean multiple) {
if (multiple || checkPhotosPermissions(call)) {
private void openPhotos(final PluginCall call, boolean multiple, boolean skipPermission) {
if (skipPermission || checkPhotosPermissions(call)) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
intent.setType("image/*");
try {
if (multiple) {
intent.putExtra("multi-pick", multiple);
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/*" });
startActivityForResult(call, intent, "processPickedImages");
} else {
startActivityForResult(call, intent, "processPickedImage");
Expand Down Expand Up @@ -347,6 +353,29 @@ public void processPickedImages(PluginCall call, ActivityResult result) {
} else {
photos.put(processResult);
}
} else if (data.getExtras() != null) {
Bundle bundle = data.getExtras();
if (bundle.keySet().contains("selectedItems")) {
ArrayList<Parcelable> fileUris = bundle.getParcelableArrayList("selectedItems");
if (fileUris != null) {
for (Parcelable fileUri : fileUris) {
if (fileUri instanceof Uri) {
Uri imageUri = (Uri) fileUri;
try {
JSObject processResult = processPickedImages(imageUri);
if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
call.reject(processResult.getString("error"));
return;
} else {
photos.put(processResult);
}
} catch (SecurityException ex) {
call.reject("SecurityException");
}
}
}
}
}
}
ret.put("photos", photos);
call.resolve(ret);
Expand Down

0 comments on commit fd059fc

Please sign in to comment.