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");
|
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");
|
||||||
|
};
|
||||||
@@ -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');
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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
5
camera/camera.d.ts
vendored
@@ -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.
|
||||||
|
|||||||
@@ -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