2012-04-16 17 views
1

Android携帯でphonegapを使用して画像をキャプチャします。 Phonegapページに掲載されたコードを試しますが、カメラは表示されません。どんな助けもありがとうございます。ありがとうございます。phonegapを使用してAndroid携帯にカメラを表示する方法

それはあなたがあなたのAndroidMenifestファイルのアクセス許可とカメラ機能を追加しました

It is the display on my phone, there is no camera

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Capture Photo</title> 

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

    var pictureSource; // picture source 
    var destinationType; // sets the format of returned value 

    // Wait for Cordova to connect with the device 
    // 
    document.addEventListener("deviceready",onDeviceReady,false); 

    // Cordova 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) { 
     // 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 = "data:image/jpeg;base64," + imageData; 
    } 

    // 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.DATA_URL }); 
    } 

    // 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.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); 
    } 

    </script> 
    </head> 
    <body> 
    <button onclick="capturePhoto();">Capture Photo</button> <br> 
    <button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br> 
    <button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br> 
    <button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br> 
    <img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> 
    <img style="display:none;" id="largeImage" src="" /> 
    </body> 
</html> 
+0

:ああ、あなた

は、ここに記載されている解決策のいくつかを試みることができますか? –

+0

ありがとう、私は問題を解決しました。私はPhonegap1.0.0を試して、それは動作します。どうしてか分かりません。 Phonegap1.6に何か問題がありますか? –

+0

1.6で何が問題になっているのか把握しておくといいでしょう。 logcatの手順はできますか? –

答えて

0

私の携帯電話に表示されますか? 追加しなかった場合は、もう一度お試しください。

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" /> 
<uses-feature android:name="android.hardware.camera.autofocus" /> 
6

どちらもあなたのcapturePhoto()capturePhotoEdit()機能がdestinationTypeを更新する必要があります。

navigator.camera.getPicture(
    onPhotoDataSuccess, 
    onFail, 
    { 
     quality: 50, 
     destinationType.DATA_URL 
    } 
); 

はあなたのコードで

navigator.camera.getPicture(
    onPhotoDataSuccess, 
    onFail, 
    { 
     quality: 50, 
     destinationType: destinationType.DATA_URL 
    } 
); 
0

はコルドバのバージョンを変更し、このようにする必要があります。 今度は "cordova-1.6.0.js" を "cordova-2.5.0.js"に変更してください それ以降はうまくいくと思います。私は同じ問題を抱えている。この

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

よう は、私が今働いてgetPhoto()関数を持っているが、それでも(cameraPhotoを取得することはできません)またはcameraPhotoEdit()関数は、作業します。私はこのポストなどですべてのことを聞いたことがあります。あなたがカメラのいずれかのボタンをクリックしたときには、「ADB logcat」で参照してくださいかどう

Phonegap Camera API Cannot Read Property data url of undefined

関連する問題