diff --git a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java index 306c99ed35a..87ec0194fcf 100644 --- a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java +++ b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java @@ -241,6 +241,7 @@ public class MediaModule extends KrollModule implements Handler.Callback private static String mediaType = MEDIA_TYPE_PHOTO; private static ContentResolver contentResolver; private boolean useCameraX = false; + private static boolean pathOnly = false; public MediaModule() { @@ -1116,6 +1117,15 @@ public void openPhotoGallery(KrollDict options) TiIntentWrapper galleryIntent = new TiIntentWrapper(new Intent()); galleryIntent.getIntent().setAction(Intent.ACTION_GET_CONTENT); + if (options.containsKeyAndNotNull(TiC.PROPERTY_MAX_IMAGES) + && options.containsKey(TiC.PROPERTY_ALLOW_MULTIPLE) + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + // set max image count + galleryIntent = new TiIntentWrapper(new Intent(MediaStore.ACTION_PICK_IMAGES)); + galleryIntent.getIntent() + .putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, options.getInt(TiC.PROPERTY_MAX_IMAGES)); + } + boolean isSelectingPhoto = false; boolean isSelectingVideo = false; if (options.containsKey(TiC.PROPERTY_MEDIA_TYPES)) { @@ -1163,6 +1173,11 @@ public void openPhotoGallery(KrollDict options) galleryIntent.getIntent().putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple); } + pathOnly = false; + if (options.containsKeyAndNotNull(TiC.PROPERTY_PATH_ONLY)) { + pathOnly = options.getBoolean(TiC.PROPERTY_PATH_ONLY); + } + final int code = allowMultiple ? PICK_IMAGE_MULTIPLE : PICK_IMAGE_SINGLE; activitySupport.launchActivityForResult(galleryIntent.getIntent(), code, new TiActivityResultHandler() { @@ -1401,16 +1416,18 @@ protected static KrollDict createDictForImage(TiBlob imageData, String mimeType) d.put("width", width); d.put("height", height); - // Add the image/video's crop dimensiosn to the dictionary. + // Add the image/video's crop dimension to the dictionary. KrollDict cropRect = new KrollDict(); cropRect.put("x", 0); cropRect.put("y", 0); cropRect.put("width", width); cropRect.put("height", height); d.put("cropRect", cropRect); - + d.put("path", imageData.getNativePath()); // Add the blob to the dictionary. - d.put("media", imageData); + if (!pathOnly) { + d.put("media", imageData); + } return d; } diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index 4f219b4c308..c7da4f79aa8 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -560,6 +560,7 @@ public class TiC public static final String PROPERTY_MAX_AGE = "maxAge"; public static final String PROPERTY_MAX_CLASSNAME = "maxClassname"; public static final String PROPERTY_MAX_ELEVATION = "maxElevation"; + public static final String PROPERTY_MAX_IMAGES = "maxImages"; public static final String PROPERTY_MAX_LENGTH = "maxLength"; public static final String PROPERTY_MAX_LINES = "maxLines"; public static final String PROPERTY_MAX_ROW_HEIGHT = "maxRowHeight"; @@ -640,6 +641,7 @@ public class TiC public static final String PROPERTY_PASSWORD = "password"; public static final String PROPERTY_PASSWORD_MASK = "passwordMask"; public static final String PROPERTY_PATH = "path"; + public static final String PROPERTY_PATH_ONLY = "pathOnly"; public static final String PROPERTY_PERSISTENT = "persistent"; public static final String PROPERTY_PHONE = "phone"; public static final String PROPERTY_PIN_IMAGE = "pinImage"; diff --git a/apidoc/Titanium/Media/Media.yml b/apidoc/Titanium/Media/Media.yml index 8f093d29dac..8e6a97e518e 100644 --- a/apidoc/Titanium/Media/Media.yml +++ b/apidoc/Titanium/Media/Media.yml @@ -2235,6 +2235,20 @@ properties: osver: {ios: {min: "14.0"}} since: { android: "6.0.0", iphone: "9.2.0", ipad: "9.2.0" } + - name: maxImages + summary: Specifies the number of images a user can select at maximum. + description: | + Only available on Android API 21 and above and with `allowMultiple:true` + type: Boolean + platforms: [android] + since: { android: "12.5.0" } + + - name: pathOnly + summary: Do not include the blob in the result + type: Boolean + platforms: [android] + since: { android: "12.5.0" } + - name: selectionLimit summary: Specifies number of media item that can be selected. description: | @@ -2284,6 +2298,12 @@ properties: summary: The media object, as a [Blob](Titanium.Blob). type: Titanium.Blob + - name: path + summary: The path of the image when returning data from the gallery. + type: String + platforms: [android] + since: "12.5.0" + - name: mediaType summary: The type of media, either `MEDIA_TYPE_PHOTO`, `MEDIA_TYPE_LIVEPHOTO` or `MEDIA_TYPE_VIDEO` defined in . type: String