我正在尝试拍摄照片并访问照片库,因为我的控制台没有显示任何错误,所以我不知道如何使其工作。我正在使用Phonegap,jquery和jquery mobile。
这是我的HTML
<div data-role="content">
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</div>
和我的JS
var pictureSource;
var destinationType;
//
document.addEventListener("deviceready",onDeviceReady,false);
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
//
function onPhotoDataSuccess(imageData) {
//
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onFail(message) {
alert('Failed because: ' + message);
}
答案 0 :(得分:0)
如果您正在编写Android应用程序并且想要使用手机中的硬件,则必须在AndroidManifest.xml文件中实现该应用程序的权限: 这些是一些权利:
<uses-permission android:name="android.permission.CAMERA" />
将它粘贴到AndroidManifest.xml文件中:
<application>
通常你可以在网上找到所有权限,尝试搜索官方的手机短信书。