【发布时间】:2016-08-08 14:38:21
【问题描述】:
我的 phonegap 应用程序(带有插件摄像头)在最近的 android 操作系统上运行良好,但是当我尝试在 android KitKat 或任何较旧的操作系统上使用它时,我可以从图库中选择图像,但脚本不会抓取它......任何线索?我猜 getPhoto() 函数有问题....
我的 xml:
<plugin name="cordova-plugin-camera" source="npm" spec="~2.1.1"/>
我的脚本:
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for PhoneGap to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);
// PhoneGap is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(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 = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoFileSuccess(imageData) {
// Get image handle
console.log(JSON.stringify(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 = imageData; setTimeout(color, 1000);
}
// 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 capturePhotoWithData() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
}
function capturePhotoWithFile() {
navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });
}
// A button will call this function
//
function getPhoto() {
// Retrieve image file location from specified source
navigator.camera.getPicture(onSuccess, onFail,
{ quality: 50,destinationType: Camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
function onSuccess (imageURI) {
var largeImage = document.getElementById ('smallImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
</script>
我正在 phonegap 构建上构建,我也尝试过 Intel XDK ...相同的结果..在 4.4.2 和其他 4.x 操作系统上不工作
【问题讨论】:
-
控制台跟踪中的错误是什么?
-
哦,伙计,我是应用程序开发的新手...我没有使用任何调试器(无法使其工作)而且我认为我需要使用手机,因为只有当我使用手机时才会出现问题画廊...我在我的应用程序的每个 html 页面上都准备好使用设备,可以吗?或者我必须只使用一次这个函数?
-
我完全不明白你的问题
标签: android cordova cordova-plugins