首页 文章

科尔多瓦:相机PLugin无法正常工作

提问于
浏览
0

我为我的App安装了Cordova相机插件 . 当我在我的计算机上运行index.html时,当我运行Camera函数时,它会显示'TypeError:navigator.camera is undefined' . 这可能(我不知道)发生,因为插件只适用于移动设备 . 然后我构建Cordova应用程序,没有出错......并将其安装在我的手机上 . 现在,当我点击“画廊”按钮时,也没有任何事情发生 .

我的代码

<body>
      <script type="text/javascript" charset="utf-8" src="cordova.js"></script>  
      <input type="button" value="Gallery" onclick="getPhoto()"/>
      <img id="myImage" src="#" />
<script>
function getPhoto() {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI});

function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}

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

这些都是我做的步骤(忘了一个?):

  • 创建新的cordova项目

  • 添加相机插件:cordova插件添加cordova-plugin-camera

  • 在platform / android / Manifest.xml中添加权限:

uses-permission android:name =“android.permission.CAMERA”/ uses-feature android:name =“android.hardware.camera”/ uses-feature android:name =“android.hardware.camera.autofocus”/

  • 写下我刚发布的代码

  • 构建应用程序

我忘记了什么或者为什么会出错?

1 回答

  • 0

    如果你想接收base64数据(你看起来像这样),请使用 destinationType.DATA_URL 而不是 destinationType.FILE_URI .

相关问题