Camera wont work on the deployed app


#1

Hi everyone,

I have been trying to integrate a QR-Code scanner on a Meteor app. The camera works fine when I run it over the browser but won’t work when its packaged into an APK. I have tried several packages such as https://github.com/hitchcott/meteor-qr-code-scanner, and also the source code from “https://github.com/xr0master/qrScanner”.

I get the following error on the terminal when i run the app using: "meteor run android-device --mobile-server https:serverdoman.com":`

\E chromium: [ERROR:web_contents_delegate.cc(197)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.

I have tried adding a plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="me.dispatch.crosswalk-permissions"
    version="0.1">
  <name>Cordova Crosswalk Permissions</name>
  <license>Apache 2.0 License</license>
  <author>Dispatch</author>
  <description>
    Request the necessary crosswalk permissions on Android for a Cordova project.
  </description>

  <info>
    This plugin replaces the need for adding permisions to the AndroidManifest.xml
    file when using Crosswalk with Cordova.
  </info>

  <platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest">
      <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="27" />
      <uses-permission android:name="android.permission.CAMERA"/>
      <uses-permission android:name="android.permission.RECORD_VIDEO" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
      <uses-feature android:name="android.hardware.Camera"/>
    </config-file>
  </platform>
</plugin>

Thank you so much for your help, I appreciate it!
I am ruing Meteor version 1.61 on Ubuntu 16.04.


#2

I’m using this plugin in cordova with good success: https://github.com/phonegap/phonegap-plugin-barcodescanner


#3

How do you take care of permissions to access the camera once the app is installed using an APK file. Could you also share how you installed and used it in meteor, please.


#4

Here is the function I created whenever there is a need to scan a QR Code. Note that I am using Onsen UI

import ons from 'onsenui';

export default function scanQRCode(resultCallback) {
    cordova.plugins.barcodeScanner.scan(
        resultCallback,
        scanningCancelled.bind(this, resultCallback),
        {
            preferFrontCamera: false, // iOS and Android
            showFlipCameraButton: false, // iOS and Android
            showTorchButton: true, // iOS and Android
            torchOn: false, // Android, launch with the torch switched on (if available)
            saveHistory: false, // Android, save scan history (default false)
            prompt:
                'Place the QR Code inside the scan area. Tap on the code to focus.', // Android
            resultDisplayDuration: 0, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
            formats: 'QR_CODE', // default: all but PDF_417 and RSS_EXPANDED
            disableAnimations: true, // iOS
            disableSuccessBeep: true // iOS and Android
        }
    );
}

function scanningCancelled(resultCallback, error) {
    ons
        .openActionSheet({
            title: 'Please give access to your camera',
            cancelable: false,
            buttons: [
                {
                    label: 'Allow access to proceed',
                    icon: 'fa-camera'
                },
                {
                    label: "Cancel and don't use this feaure",
                    icon: 'fa-ban'
                }
            ]
        })
        .then(index => {
            if (index === 0) {
                scanQRCode.bind(this, resultCallback)();
            } else {
                this.props.tab.removePageHandler(1);
            }
        });
}


#5

Okay thanks a lot man, ill try the barcodescanner plugin out


#6

The barcode scanner worked :slight_smile:

Thanks a lot man, there seems to be inconsistencies from most NPM packages in getting access to the underlying hardware once the apps are deployed to devices. I have noticed that most packages work well when tested via the browsers but tend not to work once the app is deployed into mobile platforms.