[英]Unable to access the camera in android device via Phonegap
我正在嘗試使用phonegap從網頁文件訪問設備的相機。 我經歷了以下步驟。
我通過以下鏈接創建了HTML和JavaScript示例文件。 http://docs.phonegap.com/en/2.9.0/cordova_camera_camera.md.html#cameraOptions
我下載了最新的phonegap 2.9.1,並將cordova文件復制到了asset / www文件夾中。
我將config.xml文件粘貼到res / xml文件夾中。
我將cordova-2.2.0.jar文件包含在libs文件夾中。
我正在從Java類中調用HTML文件。
但是它顯示以下錯誤。
03-18 15:19:00.364: E/Web Console(15868): Uncaught TypeError: Cannot read property 'DATA_URL' of undefined:92
03-18 15:19:00.864: V/WebViewInputDispatcher(15868): blockWebkitDraw
03-18 15:19:00.864: V/WebViewInputDispatcher(15868): blockWebkitDraw lockedfalse
03-18 15:19:01.169: D/webview(15868): blockWebkitViewMessage= false
03-18 15:19:01.174: E/Web Console(15868): Uncaught TypeError: Cannot read property 'DATA_URL' of undefined:92
請幫助我解決我的錯誤。
嘗試使用升級版本。 像phonegap 3.4.0
這樣的最新版本可以正常工作
首先,我懷疑使用cordova-2.2.0.jar和2.9.9.0的文檔不好,改為使用cordova-2.9.0.jar更好嗎? 只需確定:config.xml中是否包含相機功能(插件)?
也有一些有關如何解決類似問題的想法的相關問題: cordova提供TypeError:無法讀取未定義屬性'DATA_URL':68 無法讀取文件:/// android_asset / www / apis /的屬性未定義類型的'DATA_URL' camera.js:45
改變DATA_URL到FILE_URI IN getPhoto()函數
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageURI) {
// Uncomment to view the base64-encoded image data
// console.log(imageData);
// Get image handle
//
var smallImage = document.getElementById('smallImage');
// Unhide image elements
//
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = imageURI;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI , saveToPhotoAlbum: true });
}
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.