Skip to content

Commit 465c719

Browse files
Method to check to see if camera is available or not
1 parent 87c9828 commit 465c719

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

apps/tests/camera-tests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
import camera = require("camera");
33
// << camera-require
44

5+
import TKUnit = require("./TKUnit");
6+
57
export var test_takePicture = function () {
68
// >> camera-take-picture
79
camera.takePicture().then(result => {
810
// result is ImageSource
911
});
1012
// << camera-take-picture
1113
};
14+
15+
export var test_isCameraAvailable = function () {
16+
// >> camera-take-picture
17+
var availability = camera.isAvailable();
18+
TKUnit.assertTrue(availability == true || availability == false, "Availability should return a Boolean");
19+
};

camera/Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ camera.takePicture({"cameraPosition": camera.CameraPosition.BACK, "flashMode": c
88
console.log('pic canceled');
99
});
1010
11+
if(camera.isAvailable()){
12+
console.log('you may take a picture');
13+
}
1114
```

camera/camera.android.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export var takePicture = function (options?): Promise<any> {
106106
});
107107
}
108108

109+
export var isAvailable = function () {
110+
var utils: typeof utilsModule = require("utils/utils");
111+
112+
return utils.ad.getApplicationContext().getPackageManager().hasSystemFeature(android.content.pm.PackageManager.FEATURE_CAMERA)
113+
}
114+
109115
var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeight) {
110116
var sampleSize = 1;
111117
if (imageWidth > reqWidth && imageHeight > reqHeight) {

camera/camera.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ declare module "camera" {
1010
* @param options - Optional parameter for setting different camera options.
1111
*/
1212
export function takePicture(options?: CameraOptions): Promise<imageSource.ImageSource>;
13+
14+
/**
15+
* Is the camera available to use
16+
*/
17+
export function isAvailable(): Boolean;
1318

1419
export interface CameraOptions {
1520
/**

camera/camera.ios.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ export var takePicture = function (options): Promise<any> {
124124
}
125125
});
126126
}
127+
128+
export var isAvailable = function () {
129+
return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera);
130+
}

0 commit comments

Comments
 (0)