1

使用 Android 的 Phonegap1.9.0 相机应用程序。按照 phonegap 文档的步骤进行操作。但是当我启动应用程序并单击捕获手机时,什么也没有发生。

当我查看 logcatnavigator.camera.getPicture is undefined

下面指定的开发版本。

有人可以建议我遵循的步骤以及应该用于支持相机的特定版本。

HTML 代码如下:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, height=device-height, 
    initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <title>PhoneGap WP7</title>
  <link rel="stylesheet" href="master.css" type="text/css" media="screen" 
    title="no title" charset="utf-8" />

  <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>

  <script type="text/javascript" charset="utf-8" src="javascript.js"></script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
  <h1>
    VS Mag PhoneGap Photo Demo</h1>
  <button onclick="capturePhoto();">Capture a Photo</button>
  <br>


  <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">Display from Library</button><br>
  <img style="display: none; width: 200px; height: 200px;" alt="" id="capturedPhoto" src="" />
  <img style="display: none; width: 200px; height: 200px;" alt="" id="selectedFromPhotoLibrary"
    src="" />
</body>
</html>

下面是我的 JAVA 脚本代码:

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;
}

function selectPhoto(useCamera) 
{

  pictureSource = navigator.camera.PictureSourceType;
  destinationType = navigator.camera.DestinationType;

 if (useCamera) 
 { // take picture
  navigator.camera.getPicture(photoLoaded, onError, { allowEdit: true, destinationType: destinationType.FILE_URI });
 }
else 
{
// select from library
navigator.camera.getPicture(photoLoaded, onError, { allowEdit: true, sourceType: pictureSource.PHOTOLIBRARY, destinationType:
destinationType.FILE_URI });
}
}

//display image on the screen
function photoLoaded(imageData) 
    {
    var temp_image=imageData;
    document.getElementById("imageControl").src=temp_image;

    }

// Called when a photo is successfully retrieved
function onPhotoDataSuccess(imageData) {
    var capturedPhoto = document.getElementById('capturedPhoto');
    capturedPhoto.style.display = 'block';
    capturedPhoto.src = imageData;
    navigator.notification.alert("Picture Successfully Captured!");
}

// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI) {
    var selectedFromPhotoLibrary = document.getElementById('selectedFromPhotoLibrary');
    selectedFromPhotoLibrary.style.display = 'block';
    selectedFromPhotoLibrary.src = imageURI;
    navigator.notification.alert("Picture Imported Captured!");
}

function capturePhoto() {

    // Take picture using device camera and retrieve image
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });
}

// 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
    });
}
// Error Handling
function onFail(message) {
    alert('Failed because: ' + message);
}
4

0 回答 0