forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.android.ts
More file actions
28 lines (22 loc) · 1.2 KB
/
camera.android.ts
File metadata and controls
28 lines (22 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import imageSource = require("image-source");
import appModule = require("application");
var REQUEST_IMAGE_CAPTURE = 3453;
export var takePicture = function (): Promise<imageSource.ImageSource> {
return new Promise<imageSource.ImageSource>((resolve, reject) => {
try {
var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(appModule.android.context.getPackageManager()) != null) {
var previousResult = appModule.android.onActivityResult;
appModule.android.onActivityResult = (requestCode: number, resultCode: number, data: android.content.Intent) => {
appModule.android.onActivityResult = previousResult;
if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
resolve(imageSource.fromNativeSource(data.getExtras().get("data")))
}
};
appModule.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
} catch (e) {
reject(e);
}
});
}