【发布时间】:2019-01-26 16:48:25
【问题描述】:
我需要使用相机权限才能拍摄。我使用了 framework7 模板。 我尝试了一些不同的方法,但都失败了。
【问题讨论】:
标签: camera phonegap html-framework-7 camera-api
我需要使用相机权限才能拍摄。我使用了 framework7 模板。 我尝试了一些不同的方法,但都失败了。
【问题讨论】:
标签: camera phonegap html-framework-7 camera-api
使用过的插件
1.cordova-plugin-actionsheet
2.cordova-plugin-camera
设计...
<div id="Photos">
<a href="#" onclick="ImageSourceShareSheet()" style="text-decoration:none">
<p class="footermenutext">Photos</p>
</a>
</div>
Javascript
//Onclick Event for Photos Icon
function ImageSourceShareSheet() {
//Options for Customize Actionsheet
var options = {
'title': 'Select Image Source',
'buttonLabels': ['Camera', 'Photo Library'],
'addCancelButtonWithLabel': 'Cancel',
'position': [20, 40] // for iPad pass in the [x, y] position of the popover
};
window.plugins.actionsheet.show(options, callback);
}
//Actionsheet Callback function
function callback(buttonIndex) {
switch (buttonIndex) {
case 1:
capturePhoto();
break;
case 2:
SelectPhotosfromLibrary();
break;
}
}
//Take image source from Camera
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail,{
quality : 25,
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: true });
}
function SelectPhotosfromLibrary() {
window.imagePicker.getPictures(
function(results) {
alert(JSON.stringify(results));
if(results.length != 0)
{
// Photo Selected
}
else
{
// No photos Selected!
}
}, function (error) {
console.log('Error: ' + error);
}
);
}
【讨论】: