Method to check to see if camera is available or not

This commit is contained in:
Steve McNiven-Scott
2016-05-13 09:26:13 -04:00
parent 87c9828a04
commit 465c719800
5 changed files with 26 additions and 0 deletions

View File

@@ -2,6 +2,8 @@
import camera = require("camera"); import camera = require("camera");
// << camera-require // << camera-require
import TKUnit = require("./TKUnit");
export var test_takePicture = function () { export var test_takePicture = function () {
// >> camera-take-picture // >> camera-take-picture
camera.takePicture().then(result => { camera.takePicture().then(result => {
@@ -9,3 +11,9 @@ export var test_takePicture = function () {
}); });
// << camera-take-picture // << camera-take-picture
}; };
export var test_isCameraAvailable = function () {
// >> camera-take-picture
var availability = camera.isAvailable();
TKUnit.assertTrue(availability == true || availability == false, "Availability should return a Boolean");
};

View File

@@ -8,4 +8,7 @@ camera.takePicture({"cameraPosition": camera.CameraPosition.BACK, "flashMode": c
console.log('pic canceled'); console.log('pic canceled');
}); });
if(camera.isAvailable()){
console.log('you may take a picture');
}
``` ```

View File

@@ -106,6 +106,12 @@ export var takePicture = function (options?): Promise<any> {
}); });
} }
export var isAvailable = function () {
var utils: typeof utilsModule = require("utils/utils");
return utils.ad.getApplicationContext().getPackageManager().hasSystemFeature(android.content.pm.PackageManager.FEATURE_CAMERA)
}
var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeight) { var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeight) {
var sampleSize = 1; var sampleSize = 1;
if (imageWidth > reqWidth && imageHeight > reqHeight) { if (imageWidth > reqWidth && imageHeight > reqHeight) {

5
camera/camera.d.ts vendored
View File

@@ -11,6 +11,11 @@ declare module "camera" {
*/ */
export function takePicture(options?: CameraOptions): Promise<imageSource.ImageSource>; export function takePicture(options?: CameraOptions): Promise<imageSource.ImageSource>;
/**
* Is the camera available to use
*/
export function isAvailable(): Boolean;
export interface CameraOptions { export interface CameraOptions {
/** /**
* Defines the desired width (in device independent pixels) of the taken image. It should be used with height property. * Defines the desired width (in device independent pixels) of the taken image. It should be used with height property.

View File

@@ -124,3 +124,7 @@ export var takePicture = function (options): Promise<any> {
} }
}); });
} }
export var isAvailable = function () {
return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera);
}