NativeScript / NativeScript/plugins

[@nativescript/camera] cannot read property 'camera' of undefined

Aperta
#485 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
206
Fork
123
Merge medio
2g 1h
PR unite (30g)
1

Descrizione

I'm using @nativescript/camera 5.0.15 in a nativescript + angular app and I'm getting the following error just after taking a picture within my app;

cannot read property 'camera' of undefined

At the top of my service;

import { requestPermissions } from '@nativescript/camera';
import * as camera from "@nativescript/camera";

The method I use to take a picture;

    takePictureTap(args) {
        this.readyImage = "false";
        let that = this;
        requestPermissions().then(
            () => {
                let width = 2560;
                let adjusted_width = layout.toDeviceIndependentPixels(width)
                console.log("Width = " + adjusted_width);

                let height = 1920;
                let adjusted_height = layout.toDeviceIndependentPixels(height)
                console.log("Height = " + adjusted_height);

                camera.takePicture()
                    .then((imageAsset) => {
                        console.log("Taken picture: " + that.imageAssetURL(imageAsset))

                        console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height);
                        console.log("keepAspectRatio: " + imageAsset.options.keepAspectRatio);
                        console.log("Photo saved in Photos/Gallery for Android or in Camera Roll for iOS");

                        //this.saveAndSendPicture(imageAsset); // Doesn't work on OnePlus5 phone
                        this.sendPicture(this.imageAssetURL(imageAsset));
                    }, (error) => {
                        alert({title: "Image",
                               message: "Error taking picture, please try again. CODE: " + error,
                               okButtonText: "OK"});

                        console.log("Error image upload: " + error);
                    });
            },
            () => alert('permissions rejected')
        );
    }

The error happens just after takePicture is called and I take a picture using the emulator.

It was working, but then I've had to upgrade to SDK 31 so I could upload to Google playstore and this means I've had to upgrade a heap of nativescript packages.

I've added the following to my AndroidManifest.xml

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.asset.management.provider"
        android:exported="false"
        android:grantUriPermissions="true">
      <meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/provider_paths" />
    </provider>

And created a provider_paths.xml file

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <root-path
    name="root"
    path="." />
  <external-path
    name="external"
    path="."/>
  <external-files-path
    name="external_files"
    path="." />
  <cache-path
    name="cache"
    path="." />
  <external-cache-path
    name="external_cache"
    path="." />
  <files-path
    name="files"
    path="." />
</paths>

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Start with the @nativescript/camera requestPermissions and takePicture entry points, then inspect the AndroidManifest.xml provider declaration and provider_paths.xml. Reproduce the failure on the SDK 31 emulator and compare it with the pre-upgrade behavior; done means taking a picture completes without the undefined-property error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, typescript
Ambito
mobile-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.