【问题标题】:How to get the Cordovo navigator object instead of the javascript navigator object?如何获取 Cordovo 导航器对象而不是 javascript 导航器对象?
【发布时间】:2016-12-22 12:18:47
【问题描述】:

我对科尔多瓦非常陌生。我正在尝试创建一个简单的应用程序,用户可以在其中拍照,然后该照片显示在 html 图像标签中。

我遇到了一些我发现很难解决的问题:

(1)首先在android上运行这个demo mobile app时,

 navigator.camera.getPicture(onSucess, onFail, { quality: 50, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.PHOTOLIBRARY });

navigator.camera 正在重新调整 null。这是因为浏览器将 navigator 对象引用到 javascript navigator 对象而不是 cordova 对象。我该如何解决这个问题?

(2) 在 Visual Studio 中的 android 模拟器上运行时,尝试使用 imageUri 分配给时出现以下错误

代码:

function onDeviceReady() {};


    $("#takePhotobtn").click(function () {
        //  camera plugin code to open camera and display pic.
        navigator.camera.getPicture(onSucess, onFail, { quality: 50, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.PHOTOLIBRARY });
    });

    function onSucess(ImageData) {
        $("#candidatePhoto").attr("src", "data:image/jpeg;base64," + ImageData);
        alert("yes this works updated");
    }

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

错误:加载资源失败:data:image/jpeg;base64,blob:http%3A//localhost%3A4400/c78426c3-2f0e-4b9a-955c-df0005519358 加载资源失败:net::ERR_INVALID_URL

【问题讨论】:

  • 嘿,请确保在设备准备好后使用 navigator.camera。 navigator 在 deviceready 事件之后可用。
  • 我试过了,看上面的代码,没有运气

标签: cordova phonegap-plugins


【解决方案1】:

如果有人也遇到了这个问题,我会通过在我的主 index.html 中添加对 cordova.js 的引用来解决这个问题

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">    
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <title>Audit Chamber</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/javascript" src="cordova.js"></script>
  </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-31
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多