我需要相机访问权限。我使用了 framework7 模板。我尝试了一些不同的方法,但都失败了。
问问题
712 次
1 回答
1
使用插件
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);
}
);
}
于 2019-02-01T05:46:14.550 回答