phonegap相机和Android 4.4以下

时间:2016-08-08 14:38:21

标签: android cordova cordova-plugins

我的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构建,我也尝试使用英特尔XDK ......同样的结果......不适用于4.4.2和其他4.x操作系统

1 个答案:

答案 0 :(得分:0)

更新相机插件,现在可以使用了