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

use pickvisualmedia api #19

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
</config-file>

<framework src="com.android.support:appcompat-v7:27.1.1" />
<framework src="androidx.activity:activity:1.7.+" />
<framework src="org.jetbrains.kotlin:kotlin-stdlib:1.8.10" />

<source-file src="src/android/ImagePicker.java" target-dir="src/com/spoon/imagepicker" />
</platform>
Expand Down
10 changes: 7 additions & 3 deletions src/android/ImagePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;

public class ImagePicker extends CordovaPlugin {
private static final String ACTION_GET_PICTURES = "getPictures";
private static final String ACTION_HAS_READ_PERMISSION = "hasReadPermission";
Expand All @@ -65,9 +69,9 @@ public boolean execute(String action, final JSONArray args, final CallbackContex
final JSONObject params = args.getJSONObject(0);
this.maxImageCount = params.has("maximumImagesCount") ? params.getInt("maximumImagesCount") : 20;

Intent imagePickerIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
imagePickerIntent.setType("image/*");
imagePickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
PickVisualMediaRequest pickVisualMediaRequest = new PickVisualMediaRequest();
pickVisualMediaRequest.setMediaType$activity_release(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE);
Intent imagePickerIntent = new ActivityResultContracts.PickMultipleVisualMedia().createIntent(cordova.getContext(), pickVisualMediaRequest);
cordova.startActivityForResult(this, imagePickerIntent, SELECT_PICTURE);
this.showMaxLimitWarning();
return true;
Expand Down
Loading