Skip to content

Commit

Permalink
Merge pull request #291 from NativeScript/video-select-support-android
Browse files Browse the repository at this point in the history
feat: Add support for video select in android
  • Loading branch information
DimitarTodorov authored Aug 7, 2019
2 parents b0b14f8 + 4f71c08 commit 698fbfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ context
| prompt | iOS | undefined | Display prompt text when selecting assets. |
| numberOfColumnsInPortrait | iOS | 4 | Set the number of columns in Portrait orientation. |
| numberOfColumnsInLandscape | iOS | 7 | Set the number of columns in Landscape orientation. |
| mediaType | both | Any (iOS), Image (Android) | Choose whether to pick Image/Video/Any type of assets. |
| mediaType | both | Any | Choose whether to pick Image/Video/Any type of assets. |

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.

Expand Down
15 changes: 14 additions & 1 deletion src/imagepicker.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ImagePicker {
}

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

let length = this.mediaType === "*/*" ? 2 : 1;
let mimeTypes = Array.create(java.lang.String, length);

if (this.mediaType === "*/*") {
mimeTypes[0] = "image/*";
mimeTypes[1] = "video/*";
}
else {
mimeTypes[0] = this.mediaType;
}

// not in platform-declaration typings
intent.putExtra((android.content.Intent as any).EXTRA_MIME_TYPES, mimeTypes);
// TODO: Use (<any>android).content.Intent.EXTRA_ALLOW_MULTIPLE
if (this.mode === 'multiple') {
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
Expand Down

0 comments on commit 698fbfe

Please sign in to comment.