繁体   English   中英

使用phonegap检索和显示照片只能在模拟器中使用,而不能在我的手机上使用

[英]Retrieving and displaying photo with phonegap works in emulator but not on my phone

我正在使用PhonGap API拍照并显示在应用程序中。 在模拟器中一切正常(在chrome中使用Ripple扩展名),但不适用于我的手机或平板电脑(均为android)。 有人知道为什么吗?

编辑:我现在已经确定它可以拍摄并返回照片,并且正在创建画布,它只是出于某种原因而不是将图像绘制到画布上。

编辑2:在阅读以下内容后现在解决: 我如何使用Phonegap将图像加载到HTML5 Canvas上 后来的功能不起作用。 但就我而言,问题似乎不是权限。

// Called by 'Take Photo' button
function takePhoto() {
  // Take picture using device camera and retrieve image as base64-encoded string. If      
  //camera unavailable it will offer the option to retrieve a file
  navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
  destinationType: Camera.DestinationType.DATA_URL } );
}


// Displays the image on the screen   
function onSuccess (imageData) {   

alert("Hello " + imageData.length); //added this to check if anything was making it to     
///this point

    var image = document.getElementById("image");
    image.src = imageData;
    var c=document.getElementById("myCanvas");
    var ctx=c.getContext("2d");        
    ctx.drawImage(image,0,0,c.width,c.height);        
}


function onFail(message) {
  alert("Failed because: " + message);
}
    Paste this on Andorid confing.xml

    <feature name="http://api.phonegap.com/1.0/device" />
    <feature name="http://api.phonegap.com/1.0/battery"/>
    <feature name="http://api.phonegap.com/1.0/camera"/>
    <feature name="http://api.phonegap.com/1.0/contacts"/>
    <feature name="http://api.phonegap.com/1.0/file"/>
    <feature name="http://api.phonegap.com/1.0/geolocation"/>
    <feature name="http://api.phonegap.com/1.0/media"/>
    <feature name="http://api.phonegap.com/1.0/network"/>
    <feature name="http://api.phonegap.com/1.0/notification"/>

    Paste this on AndroidManifest.xml 

    uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-sdk android:minSdkVersion="7"/>
    <activity  android:configChanges="orientation|keyboardHidden" />
            <uses-permission android:name="android.permission.CAMERA" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
            <permission android:name="android.permission.ACCESS_NETWORK_STATE" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM