我是Android开发人员的新手,也是Web开发人员的新手。最近,我一直试图使用手机间隙制作一个网络应用程序,现在只需激活我的移动相机并拍照。我正在阅读“20个编程phonegap的食谱”一书。在书中有一个完全相同的食谱,但它对我不起作用。下面是我的代码。
Photos.js
var loaded = false;
alert ("In the PHOTO JS");
function onPhotosLoad() {
alert ("In the ONPHOTOLOAD JS");
// only load the camera selector on first load
if (!loaded) {
navigator.camera.getPicture(onPhotoLoadSuccess, onFail,
{
quality: 50,
encodingType: Camera.EncodingType.PNG,
destinationType: navigator.camera.DestinationType.FILE_URI
});
loaded = true;
}
}
function onPhotoLoadSuccess(photoUri) {
alert ("In the ONPHOTOLOADSUCCESS JS");
document.getElementById('photo').src = photoUri;
}
function onFail(message) {
alert('Failed because: ' + message);
}
Photos.html
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
</head>
<body>
<div data-role="page" id="contacts-page">
<div data-role="header" data-position="inline">
<h1>Photos</h1>
</div>
<img src="" id="photo" />
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="map.html">Map</a></li>
<li><a href="compass.html">Compass</a></li>
<li><a href="list.html">List</a></li>
<li><a href="contacts.html">Contacts</a></li>
<li><a href="photos.html" class="ui-btn-active">Photos</a></li>
</ul>
</div>
</div>
<script type="text/javascript" charset="utf-8" src="scripts/photos.js"></script>
</div>
</body>
</html>