从远程网站访问科尔多瓦相机

cordova camera access from remote website

我用 cordova 为 android 平台制作了一个应用程序。 在 index.html 设备就绪事件中,我从外部网站加载页面:

window.open('https://www.miosito.it/camera.php', '_self', 'location=no,clearcache=yes,toolbar=no');

在这个页面(camera.php)我想访问设备相机拍照,但是navigator.camera未定义。

插件在应用程序中正确加载,因为在 cordova 主页 index.html 中的 OnDeviceReady 事件中,此对象存在并且有效。

var app = {

    token: undefined,

    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {

        this.receivedEvent('deviceready');
        console.log(JSON.stringify(navigator));
        // here it works!!!

我哪里错了?

这里是我使用的软件版本:

cordova: 8.1.2 (cordova-lib@8.1.1)
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-fcm 2.1.2 "FCMPlugin"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-inappbrowser-camera 1.1.0 "InAppBrowser"
cordova-plugin-media 5.0.2 "Media"
cordova-plugin-media-capture 3.0.2 "Capture"
cordova-plugin-whitelist 1.3.3 "Whitelist"

有什么想法吗?

谢谢

因为它是 Cordova 项目环境之外的外部网页,所以一旦加载外部页面,您将无法使用 Cordova 插件。基本上,您的 window.open 命令完全取代了您的 Cordova 环境。