Skip to content

Commit f826156

Browse files
authored
Merge pull request #288 from NativeScript/xuhcc/android-media-type
feat(android): add support for mediaType option for android devices
2 parents caf22a4 + 602d882 commit f826156

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
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 | iOS | Any | Choose whether to pick Image/Video/Any type of assets. |
136+
| mediaType | both | Any (iOS), Image (Android) | 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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ export class ImagePicker {
146146
return this._options && this._options.mode && this._options.mode.toLowerCase() === 'single' ? 'single' : 'multiple';
147147
}
148148

149+
get mediaType(): string {
150+
const mediaType = this._options && 'mediaType' in this._options ? this._options.mediaType : ImagePickerMediaType.Image;
151+
if (mediaType === ImagePickerMediaType.Image) {
152+
return "image/*";
153+
} else if (mediaType === ImagePickerMediaType.Video) {
154+
return "video/*";
155+
} else {
156+
return "*/*";
157+
}
158+
}
159+
149160
authorize(): Promise<void> {
150161
if ((<any>android).os.Build.VERSION.SDK_INT >= 23) {
151162
return permissions.requestPermission([(<any>android).Manifest.permission.READ_EXTERNAL_STORAGE]);
@@ -214,7 +225,7 @@ export class ImagePicker {
214225

215226
let Intent = android.content.Intent;
216227
let intent = new Intent();
217-
intent.setType("image/*");
228+
intent.setType(this.mediaType);
218229

219230
// TODO: Use (<any>android).content.Intent.EXTRA_ALLOW_MULTIPLE
220231
if (this.mode === 'multiple') {

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ interface Options {
6363
numberOfColumnsInLandscape?: number;
6464

6565
/**
66-
* Set the media type (image/video/both) to pick in iOS
66+
* Set the media type (image/video/any) to pick
6767
*/
6868
mediaType?: ImagePickerMediaType;
6969

0 commit comments

Comments
 (0)