Skip to content

Commit 698fbfe

Browse files
Merge pull request #291 from NativeScript/video-select-support-android
feat: Add support for video select in android
2 parents b0b14f8 + 4f71c08 commit 698fbfe

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ context
133133
| prompt | iOS | undefined | Display prompt text when selecting assets. |
134134
| numberOfColumnsInPortrait | iOS | 4 | Set the number of columns in Portrait orientation. |
135135
| numberOfColumnsInLandscape | iOS | 7 | Set the number of columns in Landscape orientation. |
136-
| mediaType | both | Any (iOS), Image (Android) | Choose whether to pick Image/Video/Any type of assets. |
136+
| mediaType | both | Any | Choose whether to pick Image/Video/Any type of assets. |
137137

138138
The **hostView** parameter can be set to the view that hosts the image picker. Applicable in iOS only, intended to be used when open picker from a modal page.
139139

src/imagepicker.android.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class ImagePicker {
147147
}
148148

149149
get mediaType(): string {
150-
const mediaType = this._options && 'mediaType' in this._options ? this._options.mediaType : ImagePickerMediaType.Image;
150+
const mediaType = this._options && 'mediaType' in this._options ? this._options.mediaType : ImagePickerMediaType.Any;
151151
if (mediaType === ImagePickerMediaType.Image) {
152152
return "image/*";
153153
} else if (mediaType === ImagePickerMediaType.Video) {
@@ -227,6 +227,19 @@ export class ImagePicker {
227227
let intent = new Intent();
228228
intent.setType(this.mediaType);
229229

230+
let length = this.mediaType === "*/*" ? 2 : 1;
231+
let mimeTypes = Array.create(java.lang.String, length);
232+
233+
if (this.mediaType === "*/*") {
234+
mimeTypes[0] = "image/*";
235+
mimeTypes[1] = "video/*";
236+
}
237+
else {
238+
mimeTypes[0] = this.mediaType;
239+
}
240+
241+
// not in platform-declaration typings
242+
intent.putExtra((android.content.Intent as any).EXTRA_MIME_TYPES, mimeTypes);
230243
// TODO: Use (<any>android).content.Intent.EXTRA_ALLOW_MULTIPLE
231244
if (this.mode === 'multiple') {
232245
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);

0 commit comments

Comments
 (0)