mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Method to check to see if camera is available or not
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
import camera = require("camera");
|
||||
// << camera-require
|
||||
|
||||
import TKUnit = require("./TKUnit");
|
||||
|
||||
export var test_takePicture = function () {
|
||||
// >> camera-take-picture
|
||||
camera.takePicture().then(result => {
|
||||
@@ -9,3 +11,9 @@ export var test_takePicture = function () {
|
||||
});
|
||||
// << 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");
|
||||
};
|
||||
@@ -8,4 +8,7 @@ camera.takePicture({"cameraPosition": camera.CameraPosition.BACK, "flashMode": c
|
||||
console.log('pic canceled');
|
||||
});
|
||||
|
||||
if(camera.isAvailable()){
|
||||
console.log('you may take a picture');
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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 sampleSize = 1;
|
||||
if (imageWidth > reqWidth && imageHeight > reqHeight) {
|
||||
|
||||
5
camera/camera.d.ts
vendored
5
camera/camera.d.ts
vendored
@@ -10,6 +10,11 @@ declare module "camera" {
|
||||
* @param options - Optional parameter for setting different camera options.
|
||||
*/
|
||||
export function takePicture(options?: CameraOptions): Promise<imageSource.ImageSource>;
|
||||
|
||||
/**
|
||||
* Is the camera available to use
|
||||
*/
|
||||
export function isAvailable(): Boolean;
|
||||
|
||||
export interface CameraOptions {
|
||||
/**
|
||||
|
||||
@@ -124,3 +124,7 @@ export var takePicture = function (options): Promise<any> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export var isAvailable = function () {
|
||||
return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user