无法读取未定义的属性“ getPicture”

蒂亚戈

在开始本主题之前,我在这里阅读了几个答案,但是所有答案都很老,没有一个起作用。

我是科尔多瓦的新手。

我正在尝试使用cordova-plugin-camera插件

我生成了apk,当我要在手机(MotoG 3-Android 6.0)上对其进行测试时,它无法打开。

使用调试显示此错误:

无法读取未定义的属性“ getPicture”

我的代码:

<!DOCTYPE html>
<html>
  <head>
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="shortcut icon" href="img/favicon.png"  />

    <title>Foto</title>
  </head>
  <body>

    <div class="app">

      <button type="button" class="btn" id="cameraApp">Take a picture</button>
      <img src="" id="myImage">


    </div>




    <script src="js/jquery-3.4.1.min.js"></script>

    <script>

      document.getElementById('cameraApp').addEventListener('click', cameraApp);
      function cameraApp() {
        navigator.camera.getPicture(onSuccess, onFail,{
          quality: 100,
          saveToPhotoAlbum: true,
          destinatinType: Camera.DestinatinType.DATA_URL
        });

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

        function onFail(message){
          alert('Falhou: ' + message);
        }
      }

    </script>


  </body>
</html>

配置文件

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.myapp.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android" >
    <name>F.C. APP</name>
    <description>
        Myapp
    </description>
    <author email="[email protected]" href="www.mysite.net">
        Hostcia.net
    </author>
    <content src="index.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:*" />
        <icon src="www/img/favicon.png" width="57" height="57" density="mdpi" />
        <custom-config-file target="AndroidManifest.xml" parent="/*">
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.NETWORK_ACCESS" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.CAMERA" />
            <uses-feature android:name="android.hardware.camera" />
            <uses-feature android:name="android.hardware.camera.autofocus" />
          </custom-config-file>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

我究竟做错了什么?

兰普拉萨特·塞尔瓦姆

navigator 设备就绪事件后可用

    <script>
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        console.log(navigator.camera);
    document.getElementById('cameraApp').addEventListener('click', cameraApp);
    }

    function cameraApp() {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
                quality: 25,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.CAMERA,
                allowEdit: true,
                encodingType: Camera.EncodingType.JPEG,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: true
            });
    }
    </script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章