Skip to content

Commit

Permalink
fix(android) Fix multiple image selection on Samsung devices
Browse files Browse the repository at this point in the history
  • Loading branch information
N0ctural committed Dec 3, 2021
1 parent 3beb75a commit 4786a3f
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ private void openPhotos(final PluginCall call, boolean multiple) {
if (multiple || checkPhotosPermissions(call)) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*"});
intent.putExtra("multi-pick", multiple);
intent.setType("image/*");
try {
if (multiple) {
Expand Down Expand Up @@ -341,6 +343,59 @@ public void processPickedImages(PluginCall call, ActivityResult result) {
call.resolve(ret);
}
);
} else if (data.getData() != null) {
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(
() -> {
JSObject ret = new JSObject();
JSArray photos = new JSArray();
Uri imageUri = data.getData();
JSObject processResult = processPickedImages(imageUri);
if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
call.reject(processResult.getString("error"));
return;
} else {
photos.put(processPickedImages(imageUri));
}

ret.put("photos", photos);
call.resolve(ret);
}
);
} else if (data.getExtras() != null) {
Bundle bundle = data.getExtras();

if (bundle.keySet().contains("selectedItems")) {
ArrayList<Parcelable> fileUris = bundle.getParcelableArrayList("selectedItems");

if (fileUris != null) {

Executor executor = Executors.newSingleThreadExecutor();
executor.execute(
() -> {
JSObject ret = new JSObject();
JSArray photos = new JSArray();

for(Parcelable fileUri : fileUris) {
if (fileUri instanceof Uri) {
Uri imageUri = (Uri) fileUri;
JSObject processResult = processPickedImages(imageUri);

if (processResult.getString("error") != null && !processResult.getString("error").isEmpty()) {
call.reject(processResult.getString("error"));
return;
} else {
photos.put(processPickedImages(imageUri));
}
}
}

ret.put("photos", photos);
call.resolve(ret);
}
);
}
}
} else {
call.reject("No images picked");
}
Expand Down

0 comments on commit 4786a3f

Please sign in to comment.