ionic-team / ionic-v3

The repo for Ionic 3.x. For the latest version of Ionic, please see https://github.com/ionic-team/ionic
Other
127 stars 85 forks source link

Native: tried calling Camera.getPicture, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator #727

Open ionitron-bot[bot] opened 5 years ago

ionitron-bot[bot] commented 5 years ago

Original issue by @aadriann on 2018-11-04T17:54:08Z

Bug Report

Ionic Info Run ionic info from a terminal/cmd prompt and paste the output below.

Ionic:

   ionic (Ionic CLI)             : 4.3.0
   Ionic Framework               : @ionic/angular 4.0.0-beta.12
   @angular-devkit/build-angular : 0.7.5
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 6.1.5
   @ionic/angular-toolkit        : 1.1.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.1, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 9 other plugins)

System:

   NodeJS : v8.9.0 (C:\Program Files\nodejs\node.exe)
   npm    : 5.5.1
   OS     : Windows 10

Describe the Bug When i try to choose some option to upload a photo i have this error: "Native: tried calling Camera.getPicture, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator"

Only happend when i generate an APK with ionic pro, in my local with ionic cordova build/run android and with cap open android works.

My imports: import { Camera, CameraOptions, PictureSourceType } from '@ionic-native/camera/ngx';

Code: this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY);

takePicture(sourceType: PictureSourceType) { const options: CameraOptions = { quality: 100, sourceType: sourceType, saveToPhotoAlbum: false, correctOrientation: true, allowEdit: true };

    // Get the data of an image
    this.camera.getPicture(options).then((imagePath) => {
        // Special handling for Android library
        if ((this.platform.is('android') || this.platform.is('ios')) && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
            this.filePath.resolveNativePath(imagePath)
                .then(filePath => {
                    let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
                    let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
                    this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
                });
        } else {
            var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
            var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
            this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
        }
    }, (err) => {
        console.error("error", err);
        this._imageService.presentToast(err);
    });
}

Previously to this error, this functionality works, but i update to ionic 4.3.0 and fails

qqaimh commented 5 years ago

how to solve it?

eymen-elkum commented 5 years ago

the same problem

Markusdreyer commented 5 years ago

try running ionic cordova run browser

TonnyBiDa commented 4 years ago

Anyone has solutions?

JoelKap commented 3 years ago

Has anyone found solution to this issue?

mikesosa commented 2 years ago

Solutions?

Mehul1437 commented 2 years ago

Any Solutions?