2015-12-31 79 views
1

我们已经尝试使用phonegap从android设备打开相机,但无法做到这一点。你能帮我们解决这个问题吗?科尔多瓦相机不能正常工作

下面是编写的代码。

<div> 
     <input class="camerabutton" id="btnCamera" value="open camera" type="button" height="100" width="100" /> 
     </div> 
      <script type="text/javascript" src="js/cordova.js"></script> 
     <script type="text/javascript" src="js/cordova_plugins.js"></script> 
     <script type="text/javascript" src="js/framework7.js"></script> 

     <script type="text/javascript"> 
     var myApp = new Framework7(); 

// Export selectors engine 
var $$ = Dom7; 

$$('.camerabutton').on('click', function() { 

     navigator.camera.getPicture(onSuccess, onFail, { 
       quality: 50 
      }); 


     function onSuccess(imageData) { 
      alert("test"); 
     } 

     function onFail(message) { 
      alert('Failed because: ' + message); 
     } 
}); 
    </script> 

Config.xml文件(假设所有的权限)

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

AndroidManifest.xml文件

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.RECORD_AUDIO" /> 
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.CAMERA" /> 
    <uses-feature android:name="android.hardware.camera" /> 
    <uses-feature android:name="android.hardware.camera.autofocus" /> 

让我们知道,如果中提到的代码的任何问题或以上的需要补充的东西。

回答

1

呵呵,在做一些研究后,我们可以解决这个问题。这是config.xml中的问题,所以我用下面提到的代码替换了它。

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.example.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>test</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="Contacts.html" /> 
    <plugin name="cordova-plugin-whitelist" spec="1" /> 
    <access origin="*" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="https://*/*" /> 
    <allow-intent href="tel:*" /> 
    <allow-intent href="sms:*" /> 
    <allow-intent href="mailto:*" /> 
    <allow-intent href="geo:*" /> 
    <platform name="android"> 
     <allow-intent href="market:*" /> 
    </platform> 
    <platform name="ios"> 
     <allow-intent href="itms:*" /> 
     <allow-intent href="itms-apps:*" /> 
    </platform> 
    <feature name="Contacts"> 
    <param name="android-package" value="org.apache.cordova.contacts.ContactManager" /> 
</feature> 
<feature name="Camera"> 
<param name="android-package" value="org.apache.cordova.CameraLauncher" /> 
</feature> 
</widget> 
+2

如果您更具体地说明您更改了哪些行,对其他人会有用 –

1

,你是否尝试添加到您的选项旁边的品质:

destinationType: Camera.DestinationType.DATA_URL 

File_uri默认是不是为我工作,直到我改变了它。

另外我的科尔多瓦相机插件不知何故死了一次。卸载插件并重新安装,立即解决了我的相机问题。

+0

我试过了上面提到的所有东西,但仍然不起作用。 –

+0

我刚碰到一个问题,相机imageData没有被保存,因为我没有在上面相同的地方在相机选项行allowEdit:true。有了allowEdit:false或没有任何东西,相机就完全打破了。 – daniel

+0

感谢您的帮助,但我的问题仍然存在。我不想要任何图像数据,我只是想打开一个摄像头,并没有打开。 –