Skip to content

refactor(android): add mimeTypes property to ImagePicker class #304

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

Merged
merged 1 commit into from
Sep 9, 2019
Merged
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
28 changes: 16 additions & 12 deletions src/imagepicker.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ export class ImagePicker {
}
}

get mimeTypes() {
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;
}
return mimeTypes;
}

authorize(): Promise<void> {
if ((<any>android).os.Build.VERSION.SDK_INT >= 23) {
return permissions.requestPermission([(<any>android).Manifest.permission.READ_EXTERNAL_STORAGE]);
Expand Down Expand Up @@ -227,19 +241,9 @@ 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);
intent.putExtra((android.content.Intent as any).EXTRA_MIME_TYPES, this.mimeTypes);

// TODO: Use (<any>android).content.Intent.EXTRA_ALLOW_MULTIPLE
if (this.mode === 'multiple') {
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
Expand Down
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { ImageAsset } from "tns-core-modules/image-asset";
import { View } from "tns-core-modules/ui/core/view/view";

export class ImagePicker {

constructor(options?: Options);

/**
* Call this before 'present' to request any additional permissions that may be necessary.
* In case of failed authorization consider notifying the user for degraded functionality.
Expand Down