1

Android用のPhonegap1.9.0カメラアプリを使用しています。phonegapのドキュメントに従って手順に従いました。しかし、アプリを起動して Capture phone をクリックしても何も起こりません。

logcatを調べるとnavigator.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 SCRIPTコードです:

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