首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法读取未定义的属性“getPicture”

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

Stack Overflow用户
提问于 2020-01-07 12:08:13
回答 1查看 520关注 0票数 1

在开始这个主题之前,我在这里读到了几个答案,但都很古老,而且都没有用。

我是科多瓦的新手。

我正在尝试使用cordova插件-相机插件

我生成apk,当我要在我的手机(MotoG 3-Android6.0)上测试它时,它没有打开。

使用debug显示了此错误:

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

这是我的代码:

代码语言:javascript
复制
<!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>

CONFIG.XML

代码语言:javascript
复制
<?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="sac@mysite.net" 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>

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-07 12:48:15

设备就绪事件后可用的navigator

代码语言:javascript
复制
    <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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59628147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档