0
我使用的是Phonegap 3,並正在使用Blackberry 10設備進行測試。我無法讓相機工作。我加入了攝像頭插件,但是當我點擊應用中的按鈕,拍攝一張照片我得到的錯誤擴展相機未找到 - Phonegap 3.0
'Failed because: Extension Camera not found.'
當我在紋波測試我得到的控制檯上的錯誤是
'Cannot read property 'PictureSourceType' of undefined' when the page first loads
和
'的ReferenceError:相機沒有定義' 試圖拍照
config.xml文件時
<?xml version='1.0' encoding='utf-8'?>
<widget id="default.app.id" version="1.0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets">
<name>Webworks Application</name>
<author>Your Name Here</author>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<license href="http://opensource.org/licenses/alphabetical">
</license>
<access subdomains="true" uri="file:///store/home" />
<access subdomains="true" uri="file:///SDCard" />
<access subdomains="true" uri="*" />
<icon src="res/icon/blackberry/icon-80.png" />
<rim:splash src="res/screen/blackberry/splash-1280x768.png" />
<rim:splash src="res/screen/blackberry/splash-720x720.png" />
<rim:splash src="res/screen/blackberry/splash-768x1280.png" />
<content src="index.html" />
<rim:permissions>
<rim:permit>use_camera</rim:permit>
<rim:permit>read_device_identifying_information</rim:permit>
<rim:permit>access_shared</rim:permit>
<rim:permit>read_geolocation</rim:permit>
<rim:permit>record_audio</rim:permit>
<rim:permit>access_pimdomain_contacts</rim:permit>
</rim:permissions>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher" />
</feature>
<feature name="NetworkStatus" value="NetworkStatus" />
</widget>
的index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" href="css/jquery.mobile-1.3.2.min.css">
<link rel="stylesheet" href="css/index.css">
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.3.2.min.js"></script>
<script src="js/mustache.js"></script>
<script src="cordova.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
</head>
<body onload="onLoad()">
<div data-role="page" id="main">
<div data-role="header" class="logo">
<img src="img/logo.png" />
</div>
<div data-role="content">
<ul id="canlist" data-role="listview">
</ul>
<a href="#newcan" data-role="button" data-icon="plus">New can</a>
</div>
<div data-role="footer" data-theme="c">
<h2 class="offline">Offline Mode</h2>
</div>
</div>
<div data-role="page" id="newcan">
<div data-role="header" class="logo">
<img src="img/logo.png" />
</div>
<div id="candetailcontent" data-role="content">
</div>
<div data-role="footer" data-theme="c">
<p>Snapcan!</p>
</div>
</div>
<script>
var candata = {cantitle:"", candetail:"", canlat:"",canlon:""};
var cantemplate = '<input type="text" name="cantitle" value="{{cantitle}}" placeholder="Can Title"/><textarea cols="40" rows="8" name="candetail" id="candetail" placeholder="Can Detail">{{candetail}}</textarea><input id="addphoto" type="button" data-icon="plus" value="Add a photo" /><img id="canimage" src="{{imagesource}}" /><div id="map">Map Placeholder</div><input id="savecan" type="button" data-theme= "a" value="Save Can"/>';
var lat,long;
var pictureSource; // picture source
var destinationType; // sets the format of returned value
$(document).on("pageinit", function(){
$('#newcan').on('pagecreate', function(event){
var html = Mustache.to_html(cantemplate, candata);
$("#candetailcontent").html(html);
});
$("#newcan").on("pageshow", function(){
navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError);
});
$("#addphoto").bind("tap", function(){
var options = {sourceType:Camera.PictureSourceType.PHOTOLIBRARY, destinationType: Camera.DestinationType.FILE_URI};
navigator.camera.getPicture(onCameraSuccess, onError, options);
});
});
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
}
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
console.log("onDeviceReady");
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Handle the online event
//
function onOnline() {
$(".offline").css("visibility", "hidden");
}
function onOffline() {
$(".offline").css("visibility", "visible");
}
function onGeoSuccess(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
var currentposition = new google.maps.LatLng(lat,lon);
var mapoptions = {
zoom: 12,
center: currentposition,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapoptions);
var marker = new google.maps.Marker({
position: currentposition,
map: map
});
}
function onCameraSuccess(imageURI){
$('#canimage').attr("src", imageURI);
$('#canimage').css("display","block");
}
function onGeoError(error){
if(error==1){
alert('Turn on Geolocation services');
}
}
function onCameraError(message){
alert(message);
}
</script>
</body>
</html>
爲什麼我不能訪問攝像頭?