Giter Club home page Giter Club logo

nativescript-camera's Introduction

NativeScript

Automated Android Tests Passing Automated iOS Tests Passing License NPM Version Discord FOSSA Status website https://good-labs.github.io/greater-good-affirmation/assets/images/badge.svg support

NativeScript empowers you to access native APIs from JavaScript directly. Currently iOS, Android, and visionOS runtimes are provided for rich mobile development across a variety of diverse use cases.

FOSSA Status

Contribute

  1. Setup your local development environment

  2. Clone to contribute:

$ git clone https://github.com/NativeScript/NativeScript.git
$ cd NativeScript

# setup workspace for development
$ npm run setup

# list all available commands to run
$ npm start

We love you and your pull requests ๐Ÿค—. Please follow our contributing guide and see our code of governance to become as involved as you want to be.

@nativescript/*

Quick Links

Other source repos

Outside the source centralized in this repo, NativeScript consists of a few other source repos. Here are the major ones:

  • iOS and visionOS Runtime Empowers JavaScript code to be executed on iOS and visionOS devices written in a mix of C++, Objective-C, and Swift.
  • Android Runtime Empowers JavaScript code to be executed on Android devices written in a mix of C++, Java and Kotlin.
  • CLI Command-line interface empowering you to create, build, and run apps using NativeScript.
  • Docs Documentation available at http://docs.nativescript.org/ written in Markdown.
  • Plugins Various TSC managed plugins. Also a good reference is the plugin marketplace with several additional plugins.
  • Firebase Modular Firebase ๐Ÿ”ฅ implementation for supported platforms.
  • ML Kit Google's ML Kit SDKs for supported platforms.
  • Payments In-App Purchase, Subscriptions, Google Pay and Apple Pay.
  • Artwork Want to use our logo or colors? Feel free to use any of our ready-to-use media material.

Copyright notice

Copyright OpenJS Foundation and NativeScript contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarksโ„ข or registeredยฎ trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy

Made with โค๏ธ

nativescript-camera's People

Contributors

adjenkov avatar dimitartodorov avatar dtopuzov avatar eddyverbruggen avatar elena-p avatar etabakov avatar lini avatar luizbills avatar msaravitz avatar nathanwalker avatar nickiliev avatar nsplugins avatar shiv19 avatar surdu avatar tbozhikov avatar tgpetrov avatar tsonevn avatar vladimiramiorkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nativescript-camera's Issues

tns run android fails to build after adding the plugin.

I keep getting the following error after adding the plugin. If I remove the plugin it works fine. Can you please let me know if there are any more dependencies that I need to install

	C:\A2ZMobile\devmain\A2Z.FieldCompass\A2Z.FieldCompass\A2Z.FieldCompass\platforms\android\src\F0\AndroidManifest.xml:48:4-72 Error:
	Attribute provider#android.support.v4.content.FileProvider@authorities value=(com.A2ZFieldServices.FieldCompass.provider) from AndroidManifest.xml:48:4-72
	is also present at AndroidManifest.xml:48:4-72 value=(com.A2ZFieldServices.FieldCompass.fileprovider).
	Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:4:3-12:14 to override.

Image custom size is not working

I changed the code of the CameraTest in this way:

export function onTakePictureTap(args: EventData) {
    let page = <Page>(<View>args.object).page;
    let saveToGallery = page.bindingContext.get("saveToGallery");
    takePicture({width: 180, height: 180, keepAspectRatio: false, saveToGallery: saveToGallery}).
        then((imageAsset) => {
            let source = new ImageSource();
            source.fromAsset(imageAsset).then(source => {
                console.log("Size: " + source.width + "x" + source.height);
            });
            page.bindingContext.set("cameraImage", imageAsset);
        }, 
        (err) => {
            console.log("Error -> " + err.message);
        });
}

which should produce an square image, but says: CONSOLE LOG file:///app/main-page.js:25:24: Size: 375x667

and here is how it looks:

simulator screen shot oct 19 2016 10 41 03

Cannot find image-asset module

I'm attempting to test this on an Android device with NativeScript Angular. I get the following error:

 node_modules/nativescript-camera/nativescript-camera.d.ts(1,29): error TS2307: Cannot find module 'image-asset'.

I installed the plugin using the tns plugin install nativescript-camera as described in the src\README.md.
I didn't see in the example project where this module was included. Is image-assset perhaps not part of Nativescript Angular?

Below is some information about my app.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                                                           
โ”‚ Component        โ”‚ Current version โ”‚ Latest version โ”‚ Information โ”‚                                                                                           
โ”‚ nativescript     โ”‚ 2.3.0           โ”‚ 2.3.0          โ”‚ Up to date  โ”‚                                                                                           
โ”‚ tns-core-modules โ”‚ 2.3.0           โ”‚ 2.3.0          โ”‚ Up to date  โ”‚                                                                                           
โ”‚ tns-android      โ”‚ 2.3.0           โ”‚ 2.3.0          โ”‚ Up to date  โ”‚                                                                                           
โ”‚ tns-ios          โ”‚ 2.3.0           โ”‚ 2.3.0          โ”‚ Up to date  โ”‚                                                                                           
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      
Dependencies:                                                                                                                                                   
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                                                                           
โ”‚ Plugin                            โ”‚ Version       โ”‚                                                                                                           
โ”‚ @angular/common                   โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/compiler                 โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/core                     โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/forms                    โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/http                     โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/platform-browser         โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/platform-browser-dynamic โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/platform-server          โ”‚ 2.0.0         โ”‚                                                                                                           
โ”‚ @angular/router                   โ”‚ 3.0.0         โ”‚                                                                                                           
โ”‚ email-validator                   โ”‚ ^1.0.4        โ”‚                                                                                                           
โ”‚ moment                            โ”‚ ^2.15.1       โ”‚                                                                                                           
โ”‚ nativescript-angular              โ”‚ ^1.0.1        โ”‚                                                                                                           
โ”‚ nativescript-camera               โ”‚ 0.0.3         โ”‚                                                                                                           
โ”‚ nativescript-geolocation          โ”‚ 0.0.13        โ”‚                                                                                                           
โ”‚ nativescript-mapbox               โ”‚ ^1.5.0        โ”‚                                                                                                           
โ”‚ nativescript-plugin-firebase      โ”‚ ^3.7.1        โ”‚                                                                                                           
โ”‚ nativescript-ripple               โ”‚ ^1.0.1        โ”‚                                                                                                           
โ”‚ nativescript-telerik-ui           โ”‚ ^1.4.1        โ”‚                                                                                                           
โ”‚ reflect-metadata                  โ”‚ ^0.1.5        โ”‚                                                                                                           
โ”‚ rxjs                              โ”‚ 5.0.0-beta.12 โ”‚                                                                                                           
โ”‚ tns-core-modules                  โ”‚ ^2.3.0        โ”‚                                                                                                           
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                                                                           
Dev Dependencies:                                                                                                                                               
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                                                                                       
โ”‚ Plugin                      โ”‚ Version โ”‚                                                                                                                       
โ”‚ babel-traverse              โ”‚ ^6.13.0 โ”‚                                                                                                                       
โ”‚ babel-types                 โ”‚ ^6.13.0 โ”‚                                                                                                                       
โ”‚ babylon                     โ”‚ ^6.9.0  โ”‚                                                                                                                       
โ”‚ codelyzer                   โ”‚ 0.0.28  โ”‚                                                                                                                       
โ”‚ lazy                        โ”‚ 1.0.11  โ”‚                                                                                                                       
โ”‚ nativescript-dev-typescript โ”‚ ^0.3.2  โ”‚                                                                                                                       
โ”‚ tslint                      โ”‚ ^3.15.1 โ”‚                                                                                                                       
โ”‚ typescript                  โ”‚ 2.0.3   โ”‚                                                                                                                       
โ”‚ zone.js                     โ”‚ ^0.6.21 โ”‚                                                                                                                       
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Camera still saving image to gallery even when setted to dont save

From @dzfweb on March 27, 2017 18:55

Apparently CameraOptions is not working correctly.
Camera still saving image to gallery even when setted to dont save.
The width and height is not working as configured too.

My code:

takePhoto(args) {
        let options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: false };
        let imageView = args.object.page.getViewById('image');
        camera.takePicture(options).
        then((imageAsset ) => {
            let source = new ImageSourceModule.ImageSource();
            source.fromAsset(imageAsset).then((source) => {
                console.log(`Size: ${source.width}x${source.height}`);
            });
            this.checkout.photo = source.toBase64String('png');
            imageView.src = imageAsset;
        }).catch((err) => {
            console.log('Error -> ' + err.message);
        });
    }

Copied from original issue: NativeScript/NativeScript#3883

imageAsset is undefined

on iOS 10 and android 4.0+ both real devices I cannot get any data returned from imageAsset after takePicture. It simply always returns undefined which makes it impossible to save the file to the app filesystem or to work further on the image to convert to base64 etc.

Here's an error from a simple binding example:

CONSOLE LOG file:///app/views/e/ason/ason.js:102:20: Error -> undefined is not an object (evaluating 'page.bindingContext = ({imageSrc: imageAsset})')

All the errors generally match that format - all feature the undefined issue

Pictures are saved to file system but never deleted

I had a problem with my app, where for every picture taken, the storage consumption would grow of about 5 MB, on Android 7.0 (Samsung J5).
Tried debugging, to see if I made a mistake or something, and found out that every picture you take is saved in a folder (path specified with this line)
picturePath = utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/" + "NSIMG_" + dateStamp + ".jpg";

Wouldn't it be better if the plugin did either:

  1. Remove the file after consumption
  2. Have a "filepath" property in the options, in order to write the file directly to the folder you need it to be.

As of now I'm removing the file as soon as I get the ImageSource from ImageAsset.

nativescript-camera restart app

From @bumbella on November 4, 2017 9:19

Hi,
I use nativescript-angular
tns info:
โ”‚ nativescript โ”‚ 3.3.0 โ”‚ 3.3.0 โ”‚ Up to date โ”‚
โ”‚ tns-core-modules โ”‚ 3.3.0 โ”‚ 3.3.0 โ”‚ Up to date โ”‚
โ”‚ tns-android โ”‚ 3.3.0 โ”‚ 3.3.0 โ”‚ Up to date โ”‚
โ”‚ tns-ios โ”‚ 3.3.0 โ”‚ 3.3.0 โ”‚ Up to date โ”‚

Camera version:
nativescript-camera: "^3.1.3"

I take a picture on android 7.1.1 Nokia 5 phone but the app is restart.
I tested all iphone and Android 6.0.0 HtC Desire 626 Genymotion Android 6.0.0 emulator and code works fine and not restart but Nokia 5 android 7.1.1 crash when take a photo.
The photo not save to gallery when I turn saveToGallery to true.
Terminal send:

ActivityManager: Process hu.xxx.xxx (pid 4096) has died
ActivityManager: cleanUpApplicationRecord -- 4096

Please help me what is the wrong in my code:

let options = { width: 100, height: 100, keepAspectRatio: false, saveToGallery: false };
        takePicture( options )
            .then( picture => {
                console.log("ok")
                //this.cameraImageSrc = picture;
                //this.searchItemsbyPicture(picture);
            }).catch((err) => {
            console.log("Error -> " + err.message);
        });

Thanx, Miklos

Copied from original issue: NativeScript/nativescript-angular#1075

Camera saving images to gallery on 3.2.1 despite saveToGallery being false

Android v7.0.0
Real device - LG G5
nativescript - 3.3.0
tns-core-modules - 3.3.0
tns-android - 3.3.0
nativescript-camera - 3.2.1

I request the permissions at the end of the ngOnInit(), i then click a button to call takeImage() which is as follows

takeImage() {
    cameraModule.takePicture({
        width: 100,
        height: 150,
        keepAspectRatio: true,
        saveToGallery: false
    }).then(imageAsset => {
        imageSource.fromAsset(imageAsset)
            .then(res => {
                this.displayPicture(res);
            }).then(
            () => {
                //Do code to display new elements
            })
    });
}

Currently only tested on android but not on ios

Camera selfie mode and capture the selfie in a customized frame

I have a screen in my app where user can upload his profile pic. whenever he opens this screen, camera should open directly in selfie mode (without any user interaction) and should allow him to take his selfie. The selfie captured by camera should be loaded in a frame for preview.

Can someone please suggest:

  1. how can I load the camera to directly capture selfie?
  2. how can I load the selfie captured by camera in a frame of my screen?

Thanks.

Get image size in Nativescript ios

Hi friends i uploaded image using imagepicker in Nativescript app in ios. i can successfully upload the image. but i want to restrict the size of the image.that is when i select the image before save i want to check whether it is less than or greater than 2MB. is there any way to do this.

here i have include my code snippet , pls anyone answer me,

startSelection(context) {
         context
             .authorize()
             .then(() => {

                 imageItems.length = 0;
                 return context.present();
             })
           .then(selection => {

                 selection.forEach(selected_item => {
                     selected_item.getImage().then(imagesource => {
                         let folder = fs.knownFolders.documents();
                         let path = fs.path.join(folder.path, "Test" + counter + ".png");
                         let saved = imagesource.saveToFile(path, "png");

                         if (saved) {

                             if (this.photoType == "frntImg")
                                 this.profilePoto = imagesource;
                             else if (this.photoType == "sideView")
                                 this.sideView = imagesource;
                             var task = this.sendImages("Image" + counter + ".png", path, imagesource);

                         }
                         counter++;
                     })

                 });
             }).catch(function (e) {
                 console.error(e);
             });

     }

    sendImages(uri, fileUri, imgStream) {
        this.imageName = this.extractImageName(fileUri);
        var userId = this.userObj.id;
        var self = this;
        var request = {
            url: this.config.ServerWithApiUrl + "setProfilePicForMob",
            //url: "http://httpbin.org/post",
            method: "POST",
            body: this.imageName,
            headers: {
                "Content-Type": "application/octet-stream",
                "fileName": uri,
                "userId": this.userObj.id,
                "photoType": this.photoType
            },
            description: "{ 'uploading': " + this.imageName + " }",
        };
        var task = session.uploadFile(fileUri, request);
        task.on("progress", this.logEvent);
        task.on("error", this.logEvent);
        task.on("responded", function (e) {
            if (self.photoType == "frntImg") {
                self.userObj.photoLocation = e.data;
                alert("Uploaded Successfully");
            } else if (self.photoType == "sideView") {
                self.userObj.sideViewPhoto = e.data;
                alert("Uploaded Successfully");
            }

            ApplicationSettings.setString("userInfo", JSON.stringify(self.userObj));

        });
        task.on("complete", this.logEvent);


        return task;
    }

    public tData;
    logEvent(e) {
        //console.log("currentBytes: " + e.currentBytes);
        //console.log("totalBytes: " + e.totalBytes);
        //console.log("eventName: " + e.eventName);
        if (e.eventName == 'complete') {
            //console.log('upload completed');
        } else if (e.eventName == 'error') {
            //console.log('upload error');
        } else if (e.eventName == 'progress') {
            //console.log("progress");
        } else if (e.eventName == 'responded') {
            this.tData = JSON.parse(e.data);
        }

    }

    extractImageName(fileUri) {
        var pattern = /[^/]*$/;
        var imageName = fileUri.match(pattern);

        return imageName;
    }

Camera crashes on clicking Second Picture in App?

I have a module which include clicking picture and displaying it and then sending it back to server.
The first time everything goes smooth but if i go back and edit the image and click another picture the app crashes.

4516139756590974505-account_id 2

this is the error im getting any help? thanks

The permissions are not correctly added to the Info.plist

I don't know why, but the permissions requested are not automatically added to the application generated. I mean, the plugins infrastructure is supposed to add the permissions requested by the plugin.

I'm using

Steps to reproduce in the TestCamera app:

  1. Remove everything (rm -rf node_modules/ lib/ hooks/ platforms/)
  2. npm i
  3. tns prepare ios
  4. Check out the permissions in XCode and they will not be there:

screen shot 2016-10-22 at 08 40 57

By the way, if you do the same steps but with the permissions in the Info.plist of the CameraTest (app/App_Resources/iOS/Info.plist) they do appear:

    <key>NSPhotoLibraryUsageDescription</key>
    <string>Requires access to photo library.</string>
    <key>NSCameraUsageDescription</key>
    <string>Requires access to camera.</string>

screen shot 2016-10-22 at 08 45 55

The plugin has a problem with webpack

When I introduce webpack on my project it raises an exception on webpack execution:

Project successfully built
Successfully deployed on device with identifier '00A4117D-42D7-4D34-A741-4D4FAA4286CD'.
Oct 19 20:50:50 MacBook-Pro-de-Ignacio gyntoclient[43512]: 1   0x1074468d7 -[TNSRuntime executeModule:]
Oct 19 20:50:50 MacBook-Pro-de-Ignacio gyntoclient[43512]: 2   0x1045191b2 main
Oct 19 20:50:50 MacBook-Pro-de-Ignacio gyntoclient[43512]: 3   0x109d7e92d start
Oct 19 20:50:50 MacBook-Pro-de-Ignacio gyntoclient[43512]: file:///app/bundle.js:130314:26: JS ERROR TypeError: Attempted to assign to readonly property.
Oct 19 20:50:50 MacBook-Pro-de-Ignacio com.apple.CoreSimulator.SimDevice.00A4117D-42D7-4D34-A741-4D4FAA4286CD.launchd_sim[5678] (UIKitApplication:com.gynto.client[0x5e6e][43512]): Service exited due to signal: Segmentation fault: 11

Here is a section of the webpack bundle:

/*!***********************************************************!*\
  !*** ../~/nativescript-camera/nativescript-camera.ios.js ***!
  \***********************************************************/
/***/ function(module, exports, __webpack_require__) {

    "use strict";
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };

Removing "use strict"; seems to solve the problem as per @hdeshev on here NativeScript/nativescript-geolocation#32, but this is not the underlying problem I guess.

The sample problem arose also:

(Android) Back button modal closing event

Hello,
when open the camera view and then click the back button to close it, I don't have any even to know that I've closed the view, is there a way to know when this happens?

Thanks,
Dem

ios takepicture twice errors

When takepicture is called for the second time, it errors.

Error happens only in iPhone 6 10.2, works fine in android.

My environment

"nativescript-camera": "0.0.8",
Component โ”‚ Current version โ”‚ Latest version โ”‚ Information โ”‚
โ”‚ nativescript โ”‚ 2.4.2 โ”‚ 2.4.2 โ”‚ Up to date โ”‚
โ”‚ tns-core-modules โ”‚ 2.4.2 โ”‚ 2.4.3 โ”‚ Update available โ”‚
โ”‚ tns-android โ”‚ 2.4.1 โ”‚ 2.4.1 โ”‚ Up to date โ”‚
โ”‚ tns-ios โ”‚ 2.4.0 โ”‚ 2.4.0 โ”‚ Up to date

My code

viewModel.camOnTap = function () {
        console.log("inside camOntap");
        cameraModule.requestPermissions();
        //console.log(cameraModule.isAvailable());
        var options = { width: 100, height: 100, keepAspectRatio: true };
        //var curImageData ="" ;
        cameraModule.takePicture().then(imageAsset => {
            console.log("Result is an image asset instance"+imageAsset);
            viewModel.set("myImage", imageAsset);
            imageSource.fromAsset(imageAsset).then(res => {
                console.log(res.toBase64String(enums.ImageFormat.png));
                viewModel.imageData = res.toBase64String(enums.ImageFormat.png);
            })
        }).catch(function (err) {
            console.log("Error -> " + err.message);
        });
    }

Error

1   0x10bc53f6b NativeScript::FFICallback<NativeScript::ObjCBlockCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
2   0x10c3ed90e ffi_closure_unix64_inner
3   0x10c3ee2c2 ffi_closure_unix64
4   0x110a57808 _dispatch_call_block_and_release
5   0x110a7912e _dispatch_client_callout
6   0x110a5f1f8 _dispatch_queue_override_invoke
7   0x110a609dc _dispatch_root_queue_drain
8   0x110a60782 _dispatch_worker_thread3
9   0x110e55712 _pthread_wqthread
10  0x110e551ed start_wqthread
file:///app/tns_modules/nativescript-camera/nativescript-camera.js:88:19: JS ERROR TypeError: undefined is not an object (evaluating 'imageAs
Dec 17 18:01:29 geetha-mba com.apple.CoreSimulator.SimDevice.E9EAFE5B-0707-4233-B499-23407321CB4C.launchd_sim[3026] (UIKitApplication:com.tra
ation.nativescript[0xb4de][27270]): Service exited due to Segmentation fault: 11

The plugin does not allow to control where to pick the pictures (camera, library, etc.)

I noticed that when I opened the CamaraTest app at the device and the emulator (same OS = iOS 10 / same Phone = IPhone6) it does different things, here are the 2 screenshots, in 1 case it opens the photo library, in the other, it does open the camera app.

In iOS this is because it is switching automatically the UIImagePickerControllerSourceType, no so familiar with the same on Android

Real device:
real_phone_screenshot

Emulator:
emulator_screenshot

[Crash] After taking more then three pictures on a device with Android API level 24 or later

The Issue could be reproduced while taking four pictures in sequence while using Android device with API level 24 or later. The application will crash with the following error:

System.err: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3453, result=-1, data=null} to activity {com.A2ZFieldServices.FieldCompass/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
System.err: Calling js method onActivityResult failed

System.err: 
System.err: Error: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.A2ZFieldServices.FieldCompass/files/NSIMG_20170927_152028.jpg (No such file or directory)

System.err:     java.io.FileInputStream.open(Native Method)

System.err:     java.io.FileInputStream.<init>(FileInputStream.java:146)
System.err:     java.io.FileInputStream.<init>(FileInputStream.java:99)
System.err:     android.media.ExifInterface.<init>(ExifInterface.java:1106)
System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1084)

System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:966)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:953)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:937)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:929)

System.err:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
System.err:     android.app.Activity.dispatchActivityResult(Activity.java:6942)
System.err:     android.app.ActivityThread.deliverResults(ActivityThread.java:4102)
System.err:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4149)
System.err:     android.app.ActivityThread.-wrap20(ActivityThread.java)
System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
System.err:     android.os.Handler.dispatchMessage(Handler.java:102)

System.err:     android.os.Looper.loop(Looper.java:154)
System.err:     android.app.ActivityThread.main(ActivityThread.java:6154)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)

System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
System.err: File: "file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/nativescript-camera/nativescript-camera.js, line: 79, column: 35

System.err: 
System.err: StackTrace: 

System.err: 	Frame: function:'', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/nativescript-camera/nativescript-camera.js', line: 79, column: 36
System.err: 	Frame: function:'Observable.notify', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
System.err: 	Frame: function:'ActivityCallbacksImplementation.onActivityResult', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 673, column: 44
System.err: 	Frame: function:'NativeScriptActivity.onActivityResult', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 41, column: 25
System.err: 
System.err: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4106)
System.err: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4149)
System.err: 	at android.app.ActivityThread.-wrap20(ActivityThread.java)
System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
System.err: 	at android.os.Handler.dispatchMessage(Handler.java:102)
System.err: 	at android.os.Looper.loop(Looper.java:154)
System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6154)
System.err: 	at java.lang.reflect.Method.invoke(Native Method)
System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
System.err: Caused by: com.tns.NativeScriptException: 
System.err: Calling js method onActivityResult failed
System.err: 

System.err: Error: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.A2ZFieldServices.FieldCompass/files/NSIMG_20170927_152028.jpg (No such file or directory)
System.err:     java.io.FileInputStream.open(Native Method)
System.err:     java.io.FileInputStream.<init>(FileInputStream.java:146)
System.err:     java.io.FileInputStream.<init>(FileInputStream.java:99)
System.err:     android.media.ExifInterface.<init>(ExifInterface.java:1106)
System.err:     com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1084)
System.err:     com.tns.Runtime.callJSMethodImpl(Runtime.java:966)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:953)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:937)
System.err:     com.tns.Runtime.callJSMethod(Runtime.java:929)
System.err:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
System.err:     android.app.Activity.dispatchActivityResult(Activity.java:6942)
System.err:     android.app.ActivityThread.deliverResults(ActivityThread.java:4102)
System.err:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4149)
System.err:     android.app.ActivityThread.-wrap20(ActivityThread.java)
System.err:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
System.err:     android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     android.os.Looper.loop(Looper.java:154)
System.err:     android.app.ActivityThread.main(ActivityThread.java:6154)
System.err:     java.lang.reflect.Method.invoke(Native Method)
System.err:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
System.err:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
System.err: File: "file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/nativescript-camera/nativescript-camera.js, line: 79, column: 35
System.err: 
System.err: StackTrace: 
System.err: 	Frame: function:'', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/nativescript-camera/nativescript-camera.js', line: 79, column: 36
System.err: 	Frame: function:'Observable.notify', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/data/observable/observable.js', line: 103, column: 23
System.err: 	Frame: function:'ActivityCallbacksImplementation.onActivityResult', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 673, column: 44
System.err: 	Frame: function:'NativeScriptActivity.onActivityResult', file:'file:///data/data/com.A2ZFieldServices.FieldCompass/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 41, column: 25
System.err: 
System.err: 	at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1084)
System.err: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:966)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:953)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:937)
System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:929)
System.err: 	at com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
System.err: 	at android.app.Activity.dispatchActivityResult(Activity.java:6942)
System.err: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4102)
System.err: 	... 9 more
System.err: Caused by: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.A2ZFieldServices.FieldCompass/files/NSIMG_20170927_152028.jpg (No such file or directory)
System.err: 	at java.io.FileInputStream.open(Native Method)
System.err: 	at java.io.FileInputStream.<init>(FileInputStream.java:146)
System.err: 	at java.io.FileInputStream.<init>(FileInputStream.java:99)
System.err: 	at android.media.ExifInterface.<init>(ExifInterface.java:1106)
System.err: 	... 18 more
JS: App crashed:
JS: Error: The application crashed because of an uncaught exception. You can look at "stackTrace" or "nativeException" for more detailed information about the exception.


I am attaching sample project, which could be used for debugging.

project.zip

t. 1132625

camera take pickture not stored on phone

From @Leo-lay on January 18, 2017 6:42

Hi, i use the camera plugin and take pickture,and set the options saveToGallery:true but i don't see the photo in the album.

ios:10.0.2(14A456)
nativescript:2.4.0

follow is my code

onTakePhoto() {
        let options = {
            width: 600,
            height: 800,
            keepAspectRatio: false,
            saveToGallery: true
        };
        camera.takePicture(options).then(
            imageAsset => {
                console.log('imageAsset takePicture=>', imageAsset);
                // let source = imageSource.fromAsset(imageAsset);
                // this.saveFile(source);
                // this.makeImageFile(imageAsset);
                this.imageTaken = imageAsset;
                this.photoList.push(this.imageTaken);
                console.log('Size: ' + imageAsset.options.width + 'x' + imageAsset.options.height);
                // this.selections.push(imageAsset);
                console.log('imageAsset=>', JSON.stringify(imageAsset));
                this.photoList.forEach((item) => {
                    console.log('this.photoList=>', JSON.stringify(item));
                    console.log('length', this.photoList.length);
                });

            }).catch(error => {
                console.log('take photo error=>', error.message);
            });
    }

Copied from original issue: NativeScript/NativeScript#3504

How to build the sample app?

I've followed the instructions in the readme and the nativescript-camera-*.tgz is created. How do I now run the demo app?

I've tried:

$ /examples/CameraTest
$ npm install
$ tns plugin add /Users/daniel_rochelle/Documents/GitHub/repos/nativescript-camera/dist/package 
$ tns run ios

but this gives me the following error:

Copying template files...
Project successfully created.
Executing before-prepare hook from /Users/daniel_rochelle/Documents/GitHub/repos/nativescript-camera/examples/CameraTest/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.0.3
node_modules/tns-core-modules/declarations.d.ts(51,25): error TS2304: Cannot find name 'FormData'.

node_modules/tns-core-modules/declarations.d.ts(78,25): error TS2304: Cannot find name 'Blob'.

node_modules/tns-core-modules/declarations.d.ts(78,30): error TS2304: Cannot find name 'FormData'.

node_modules/tns-core-modules/declarations.d.ts(84,17): error TS2304: Cannot find name 'FormData'.

node_modules/tns-core-modules/http/http.d.ts(86,28): error TS2304: Cannot find name 'FormData'.

TypeScript compiler failed with exit code 1

Am I missing some plugins?
Thanks

Put mediaTypes as an option

Hi, I had some trouble removing the video option in the camera view
what i did was to set the mediatypes array to
imagePickerController.mediaTypes = [mediaTypes[0]];
It would be better to pass the type as an option like "public.image" or "public.movie"
and choose between them to enable or disable the photo or video option in the view
Could you add the mediaTypes array as an option or make it settable ?

takePicture method not returning promise in Android (but does in iOS)

Running the test-camera example (nativescript-camera/examples/CameraTest/app/), everything works just fine in iOS and the image (selected from the gallery) is displayed on the screen. But when I test this same code running the Android emulator, after the camera opens and I snap a photo and click on save, the photo does not display on the screen. So I tested by adding a console.log right after the promise should return to see what I'm getting back:

takePicture({width: 180, height: 180, keepAspectRatio: false, saveToGallery: saveToGallery}).
        then((imageAsset) => {
            console.log("IMAGE ASSET", imageAsset);
            let source = new imageSourceModule.ImageSource();
            source.fromAsset(imageAsset).then((source) => {
                console.log(`Size: ${source.width}x${source.height}`);
            });
            page.bindingContext.set("cameraImage", imageAsset);
        }, 
        (err) => {
            console.log("Error -> " + err.message);
        });

The IMAGE ASSET console log never shows in terminal, I mean nothing. Not even the string I passed, and there are no errors. The console.log does show in terminal when I run the app in the iOS simulator, but in Android nothing. I'm using the Android Studio virtual device (a Nexus 5X running Android 7.1).

I tried to search online to see if others have run into this issue. Couldn't find anything.

View laggy when the picture is too big

Hi everyone,

I got an issue while playing around with the camera module on my moto x play.
I took a picture with this code sample :

let options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: false };
        camera.takePicture(options)
            .then(this.zoneWrap((imageAsset:any) => {
                let image = new Image();
                image.src = imageAsset;
                this.images.push(image);
                console.log("setting image");
            }))

And then I showed it in my component :

<Image *ngFor="let asset of images" width="80" height="80" [src]="images.src.android"></Image>

The issue is, when I set my camera to 21mpx (the max resolution I have on my camera), when I come back on the view that shows the picutre, all the page is very laggy and every input take 3 to 5 sec to be executed.
When I set the camera to 13mpx, everything works fine.

I was hoping that the width and height options would resolve my problem but it doesn't change anything.

Is there a way to make the options parameters work? And why is my view all laggy when I take a picture at 21mpx?

Thanks for this awsome framework :)

Custom Camera View

Hello Friends,

i never used github to post a issue in the past so i hope i do it right.

This is not a issue, its more like a question how to solve a problem.

I only want to know if the following is possible with native script.

1.) Count taken pictures and do a custom action (upload all taken pictures) after picture x
2.) Overlay the camera with a layer, place a indicator on the layer so that users can see how many pictures left until action will be executed.

I hope you understand what want. If not please ask.

Sorry for my english.

takePicture() with specified width/height not working

We want to allow our user to take selfies in our app which we have build in Nativescript 3.1.2 (tns-core-modules 3.1.0, tns-android 3.1.1).

  1. Is there any nativescript plugin available that allows user to crop an image where user can select the area on a screen which he wants to crop? We tried searching but did not able find it.

  2. As an alternative we have tried nativescript-camera plugin (version 3.0.0) that has feature to automatically crop the image based on defined height and width as below:

     takePicture({ width: 300, height: 300, keepAspectRatio: false, saveToGallery: true }).
     then((imageAsset) => {
     	let image = new Image();
     	image.src = imageAsset;
     },
     (err) => {
     	console.log("Error -> " + err.message);
     });
    

But here we did not get image with specified height and width (in saved image in gallery OR in imageAsset object). It is always returning actual image.
I am little bit stuck over here and wondering why such a basic image manipulation functionality is not working in native script.

Please reply if anyone has any solution.

iOS: Strange behavior of #takePicture

Hi there,

somehow the functionality

camera.takePicture(...)

is a little bit strange on iOS 10.3

I use the example project provided here:

https://github.com/NativeScript/nativescript-camera/tree/master/examples/CameraTestAngular

When I call the functionality to take a picture in the in my app the camera comes up. Then I been prompted to allow the app to use the camera. If I denied it I still can make a photo and it's totally blacked and the photo is displayed. This is somehow strange, isn't it? Why isn't the camera closed then?

Even if I click the second time on "Take Picture" the camera comes up again allowing me to take a complete black photo...

I expect the camera to been closed once I don't allow the app to take a photo and the camera does not comes up again if I revoke the right before.

The application crash at moving to video

I ran the CamaraTest sample provided directly with XCode and this is the problem:

NativeScript loaded bundle file:///System/Library/Frameworks/UIKit.framework
NativeScript loaded bundle file:///System/Library/Frameworks/Foundation.framework
NativeScript loaded bundle file:///System/Library/Frameworks/QuartzCore.framework
NativeScript loaded bundle file:///System/Library/Frameworks/AVFoundation.framework
NativeScript loaded bundle file:///System/Library/Frameworks/MapKit.framework
NativeScript loaded bundle file:///System/Library/Frameworks/SceneKit.framework
NativeScript loaded bundle file:///System/Library/Frameworks/QuickLook.framework
NativeScript loaded bundle file:///System/Library/Frameworks/CoreImage.framework
NativeScript loaded bundle file:///System/Library/Frameworks/iAd.framework
NativeScript loaded bundle file:///System/Library/Frameworks/IntentsUI.framework
NativeScript loaded bundle file:///System/Library/Frameworks/NotificationCenter.framework
NativeScript loaded bundle file:///System/Library/Frameworks/CoreSpotlight.framework
NativeScript loaded bundle file:///System/Library/Frameworks/Intents.framework
NativeScript loaded bundle file:///System/Library/Frameworks/CoreLocation.framework
NativeScript loaded bundle file:///var/containers/Bundle/Application/618E38D3-F6D7-4D09-A927-780D13FA4C17/CameraTest.app/Frameworks/TNSWidgets.framework
NativeScript loaded bundle file:///System/Library/Frameworks/CoreGraphics.framework
NativeScript loaded bundle file:///System/Library/Frameworks/Photos.framework
2016-10-22 06:11:42.045573 CameraTest[2530:668464] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-10-22 06:11:42.051778 CameraTest[2530:668464] [MC] Reading from public effective user settings.
2016-10-22 06:12:06.295644 CameraTest[2530:668795] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

image-source saveToFile does not work

From @xanZ08 on May 19, 2017 13:56

Hello,
I need to capture an image via camera and save it to file, but the save option does not seem to work.

var cameraModule = require("nativescript-camera");
var fs = require('file-system');
var imageSource = require("image-source");
var enumsModule  = require('ui/enums');
var imageModule = require("ui/image");
var format = enumsModule.ImageFormat.jpeg
console.log(JSON.stringify(imageSource));
exports.takepic=function(){
    console.log('take pic');
cameraModule.takePicture({
    width: 300,
    height: 300,
    keepAspectRatio: true
}).then(function (imageAsset) {
    console.log("Image taken!");
    console.log(JSON.stringify(img));
   
     try{
    var img=imageSource.fromAsset(imageAsset);     
         console.log(JSON.stringify(img));
    var folder = fs.knownFolders.documents().path;
    console.log('folder - ', folder); // => object
    var fileName = 'img_' + new Date().getTime() + '.' + format
    var path = fs.path.join(folder, fileName);
    console.log('path - ', path); // => correct path
    
   
    img.saveToFile(path, format); // ### Execution stops here.
    console.log('saved - ', saved); 
    console.log('saved - ');
    }
    catch(e){
        console.log(e);
    }

    var imgLocal = imageSource.fromFile(path);

    pageData.camera.set("cameraImage", img);
});
}
```


The output is
```
JS: take pic
JS: Image taken!
JS: undefined
JS: {}
JS: folder -  /data/data/org.nativescript.sampleConvert/files
JS: path -  /data/data/org.nativescript.sampleConvert/files/img_1495201743140.jpeg
JS: TypeError: img.saveToFile is not a function

Any idea why is the saveToFile function is not working??

_Copied from original issue: NativeScript/NativeScript#4237_

Upload to s3 without save the photo

There is a way to take a picture with the camera module ("nativescript-camera") without saving into the storage?
I just want to uplaod it to s3 - For now I am saving it and upload the saved file into s3
so now I need to figure out how to not save it and upload the image from the app memory
I can actually save it - upload it - and remove it...But is there a better way to do that?

The plugin does not work on the device (IPhone 6 / IOS10)

I have the same application running on emulator and the device, and the photo library is not opening on the device (I do the same on the emulator and it does open).

It does show a message in the console:
"NativeScript loaded bundle file:///System/Library/Frameworks/Photos.framework"
but nothing happens.

I noticed it happens even if you just request the permissions, the application just hangs at the call

Incorrect image orientation and memory leak on Android / Galaxy S4

Please, provide the details below

camera-plugin ignores image-rotation after some pictures and then, when taking more images, makes the app crash with a memory error.

Did you verify this is a real problem by searching [Stack Overflow]

Yes.

Tell us about the problem

I have a view that takes pictures for being saved as part of a note.

In the beginnung, on my Samsung Galaxy S4, the images taken are rotated correctly. But after two or three pictures or so, it starts to ignore the orientation which results in portrait pictures being rotated by 90ยฐ CW. After that, all subsequent pictures are not rotated anymore.

Worse, this seems to go along with a memory leak, because after some more (incorrectly rotated) pictures the app crashes with

JS: ERROR Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

Other fellows had similar problems with the Cordova Camera Plugin. Unfortunately their solution relies on a setting called AllowEdit which nativescript-camera does not have. https://forum.ionicframework.com/t/camera-wrong-orientation-with-android/8583/25

I went into the nativescript-camera.android.js and put some logging there to eventually find the memory leak. What I found is the following behaviour:

First picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_171753.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Second picture (still correct, but look at the double call)

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_171828.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset

-- what happens now?

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Third picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_17202.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset

-- ???

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

Fourth picture

JS: I am requesting the image-asset...
JS: starting the promise...
JS: my picturePath_1 is  /storage/emulated/0/Android/data/com.igefa.igefago/files/NSIMG_20170922_172030.jpg
JS: starting picture Intent...
JS: finished picture Intent!
JS: starting foreground activity...

-- picture is taken here

JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  6
JS: Rotating the picture by 90 degrees
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: got activity result!
JS: got requestCode  3453  and resultCode  -1
JS: my orientation is  0
JS: will resolve asset now...
JS: resolved asset
JS: I've got the image-asset!
JS: application resumed

This behaviour stacks until the app dies with an OutOfMemory Error โ€“ the full stacktrace is shown below.

JS: ERROR Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 148804 free bytes and 145KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:69)
JS:     android.app.Activity.dispatchActivityResult(Activity.java:6549)
JS:     android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
JS:     android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
JS:     android.app.ActivityThread.access$1400(ActivityThread.java:177)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     at ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at file:///data/data/com.igefa.igefago/files/app/pages/notedetails/notedetails.component.js:177:46
JS: 
JS:     at ZoneDelegate.invoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:365:26)
JS:     at Object.onInvoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/@angular/core/bundles/core.umd.js:4132:37)
JS:     at ZoneDelegate.invoke (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:364:32)
JS:     at Zone.run (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:125:43)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:760:57
JS:     at ZoneDelegate.invokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:398:31)
JS:     at Object.onInvokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/@angular/core/bundles/core.umd.js:4123:37)
JS:     at ZoneDelegate.invokeTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:397:36)
JS:     at Zone.runTask (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:165:47)
JS:     at drainMicroTaskQueue (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:593:35)
JS: Unhandled Promise rejection: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) ; Zone: <root> ; Task: Promise.then ; Value: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStr
JS: eam(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     at ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at Object.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:189:18)
JS:     at ImageBase._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image-common.js:101:28)
JS:     at Image._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:98:56)
JS:     at Image.(anonymous function) (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:151:14)
JS:     at applyPendingNativeSetters (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:900:28)
JS:     at Object.initNativeView (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:862:9)
JS:     at Image.ViewBase.onResumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:670:22)
JS:     at Image.ViewBase._resumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:228:18)
JS:     at Image.ViewBase.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:206:14)
JS:     at Image.View.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view/view.js:62:35)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:212:19
JS: Error: Uncaught (in promise): Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS: Error: java.lang.OutOfMemoryError: Failed to allocate a 600636 byte allocation with 107296 free bytes and 104KB until OOM
JS:     dalvik.system.VMRuntime.newNonMovableArray(Native Method)
JS:     android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
JS:     android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
JS:     android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
JS:     android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:912)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:896)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:888)
JS:     com.tns.NativeScriptActivity.onStart(NativeScriptActivity.java:38)
JS:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
JS:     android.app.Activity.performStart(Activity.java:6329)
JS:     android.app.Activity.performRestart(Activity.java:6399)
JS:     android.app.Activity.performResume(Activity.java:6404)
JS:     android.app.ActivityThread.performResumeActivity(ActivityThread.java:3392)
JS:     android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3434)
JS:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
JS:     android.os.Handler.dispatchMessage(Handler.java:102)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5951)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
JS:     at ImageAsset.getImageAsync (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-asset/image-asset.js:25:53)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:32:19
JS:     at new ZoneAwarePromise (file:///data/data/com.igefa.igefago/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:776:29)
JS:     a
JS: t ImageSource.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:31:16)
JS:     at Object.fromAsset (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/image-source/image-source.js:189:18)
JS:     at ImageBase._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image-common.js:101:28)
JS:     at Image._createImageSourceFromSrc (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:98:56)
JS:     at Image.(anonymous function) (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/image/image.js:151:14)
JS:     at applyPendingNativeSetters (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:900:28)
JS:     at Object.initNativeView (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js:862:9)
JS:     at Image.ViewBase.onResumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:670:22)
JS:     at Image.ViewBase._resumeNativeUpdates (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:228:18)
JS:     at Image.ViewBase.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:206:14)
JS:     at Image.View.onLoaded (file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view/view.js:62:35)
JS:     at file:///data/data/com.igefa.igefago/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js:212:19

modified nativescripe-camera.android.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var applicationModule = require("application");
var imageAssetModule = require("image-asset");
var trace = require("trace");
var platform = require("platform");
var REQUEST_IMAGE_CAPTURE = 3453;
var REQUEST_REQUIRED_PERMISSIONS = 1234;
exports.takePicture = function (options) {
    return new Promise(function (resolve, reject) {
        try {
            console.log("starting the promise...");
            if (android.support.v4.content.ContextCompat.checkSelfPermission(applicationModule.android.currentContext, android.Manifest.permission.CAMERA) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
                reject(new Error("Application does not have permissions to use Camera"));
                return;
            }
            var types = require("utils/types");
            var utils = require("utils/utils");
            var saveToGallery_1;
            var reqWidth_1;
            var reqHeight_1;
            var shouldKeepAspectRatio_1;
            var density = utils.layout.getDisplayDensity();
            if (options) {
                saveToGallery_1 = options.saveToGallery ? true : false;
                reqWidth_1 = options.width ? options.width * density : 0;
                reqHeight_1 = options.height ? options.height * density : reqWidth_1;
                shouldKeepAspectRatio_1 = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
            }
            if (android.support.v4.content.ContextCompat.checkSelfPermission(applicationModule.android.currentContext, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
                saveToGallery_1 = false;
            }
            var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            var dateStamp = createDateTimeStamp();
            var picturePath_1;
            var nativeFile = void 0;
            var tempPictureUri = void 0;
            if (saveToGallery_1) {
                picturePath_1 = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath() + "/Camera/" + "NSIMG_" + dateStamp + ".jpg";
                nativeFile = new java.io.File(picturePath_1);
            }
            else {
                picturePath_1 = utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/" + "NSIMG_" + dateStamp + ".jpg";
                console.log("my picturePath_1 is ", picturePath_1);
                nativeFile = new java.io.File(picturePath_1);
            }
            var sdkVersionInt = parseInt(platform.device.sdkVersion);
            if (sdkVersionInt >= 21) {
                tempPictureUri = android.support.v4.content.FileProvider.getUriForFile(applicationModule.android.currentContext, applicationModule.android.nativeApp.getPackageName() + ".provider", nativeFile);
            }
            else {
                tempPictureUri = android.net.Uri.fromFile(nativeFile);
            }
            takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
            if (options && options.cameraFacing === "front") {
                takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
            }
            console.log("starting picture Intent...");
            if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {
                console.log("finished picture Intent!");
                var appModule_1 = require("application");
                appModule_1.android.on("activityResult", function (args) {
                    console.log("got activity result!");
                    var requestCode = args.requestCode;
                    var resultCode = args.resultCode;
                    if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
                        console.log("got requestCode ", requestCode , " and resultCode ", resultCode);
                        if (saveToGallery_1) {
                            try {
                                var callback = new android.media.MediaScannerConnection.OnScanCompletedListener({
                                    onScanCompleted: function (path, uri) {
                                        if (trace.isEnabled()) {
                                            trace.write("image from path " + path + " has been successfully scanned!", trace.categories.Debug);
                                        }
                                    }
                                });
                                android.media.MediaScannerConnection.scanFile(appModule_1.android.context, [picturePath_1], null, callback);
                            }
                            catch (ex) {
                                if (trace.isEnabled()) {
                                    trace.write("An error occurred while scanning file " + picturePath_1 + ": " + ex.message + "!", trace.categories.Debug);
                                }
                            }
                        }
                        var exif = new android.media.ExifInterface(picturePath_1);
                        var orientation_1 = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL);
                        console.log("my orientation is ", orientation_1);
                        if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_90) {
                            console.log("Rotating the picture by 90 degrees");
                            rotateBitmap(picturePath_1, 90);
                        }
                        else if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_180) {
                            console.log("Rotating the picture by 180 degrees");
                            rotateBitmap(picturePath_1, 180);
                        }
                        else if (orientation_1 === android.media.ExifInterface.ORIENTATION_ROTATE_270) {
                            console.log("Rotating the picture by 270 degrees");
                            rotateBitmap(picturePath_1, 270);
                        }
                        var asset = new imageAssetModule.ImageAsset(picturePath_1);
                        asset.options = {
                            width: reqWidth_1,
                            height: reqHeight_1,
                            keepAspectRatio: shouldKeepAspectRatio_1
                        };
                        console.log("will resolve asset now...");
                        resolve(asset);
                        console.log("resolved asset");
                    }
                });
                console.log("starting foreground activity...");
                appModule_1.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
        catch (e) {
            if (reject) {
                reject(e);
            }
        }
    });
};

The snippet calling the camera plugin

    private takePictureWithCamera() {
        const _that = this;
        let options = {width: 300, height: 300, keepAspectRatio: true, saveToGallery: false};
        console.log("I am requesting the image-asset...")
        camera.takePicture(options).then((imageAsset) => {
            console.log("I've got the image-asset!")
            let image = <Image>_that.noteImage.nativeElement;
            image.src = imageAsset;
            _that.note.hasImage = true;
            new ImageSource().fromAsset(imageAsset).then(imageSource => {
                _that.note.image = imageSource.toBase64String("png");
            });
        }).catch((err) => {
            console.log("Error -> " + err.message);
            if (isIOS) {
                // No error is given back for iOS
            } else {
                if (err.message === "Application does not have permissions to use Camera") {
                    dialogs.alert({
                        title: 'Kein Zugriff auf die Kamera mรถglich',
                        message: 'Bitte gestatten Sie der App den Zugriff auf die Kamera',
                        okButtonText: 'OK'
                    }).then(result => {
                        camera.requestPermissions();
                    });
                    return;
                }
            }
        });
    }

Which platform(s) does your issue occur on?

Android 5.0.1 on Samsung Galaxy S4

Please provide the following version numbers that your issue occurs with

"dependencies": {
"@ angular/animations": "4.0.1",
"@ angular/common": "4.0.1",
"@ angular/compiler": "4.0.1",
"@ angular/core": "4.0.1",
"@ angular/forms": "4.0.1",
"@ angular/http": "4.0.1",
"@ angular/platform-browser": "4.0.1",
"@ angular/platform-browser-dynamic": "4.0.1",
"@ angular/router": "4.0.1",
"@ angular/upgrade": "4.0.1",
"base-64": "^0.1.0",
"moment": "^2.18.1",
"nativescript-10hook-release-info": "^1.0.0",
"nativescript-angular": "~3.1.0",
"nativescript-badge-button": "^0.1.1",
"nativescript-camera": "^3.1.2",
"nativescript-cardview": "^2.0.2",
"nativescript-couchbase": "^1.0.18",
"nativescript-drop-down": "^3.1.0",
"nativescript-floatingactionbutton": "^3.0.1",
"nativescript-hockey-sdk": "^1.2.0",
"nativescript-hook": "^0.2.1",
"nativescript-i18n": "^0.2.2",
"nativescript-ibeacon": "0.8.1",
"nativescript-imagepicker": "^3.0.4",
"nativescript-iqkeyboardmanager": "^1.1.0",
"nativescript-loading-indicator": "^2.3.2",
"nativescript-local-notifications": "^1.2.1",
"nativescript-ngx-fonticon": "^2.2.0",
"nativescript-pulltorefresh": "^2.0.2",
"nativescript-push-notifications": "^0.1.3",
"nativescript-ripple": "^2.0.0",
"nativescript-sidedrawer": "^1.0.6",
"nativescript-snackbar": "^1.1.7",
"nativescript-statusbar": "^3.0.1",
"nativescript-telerik-ui": "3.0.4",
"nativescript-theme-core": "~1.0.2",
"nativescript-unit-test-runner": "^0.3.4",
"nativescript-web-image-cache": "^4.1.0",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.3.0",
"tns-core-modules": "^3.1.0",
"utf8": "^2.1.2",
"zone.js": "~0.8.5"
}

"tns-android": {
"version": "3.1.1"
}

node version v6.11.1

I'd be happy to hear from you on this one, guys!

Camera takePicture hangs after using nativescript-imagepicker, w/ saveToGallery: true

Using nativescript-camera and nativescript-imagepicker in same app, so maybe this issue should be posted to imagepicker module(??). Both modules work independent of each other, however, under specific conditions the camera module seems to hang with no error message, testing so far only on iOS & using NG2.

Hanging condition sequence -

  1. Use imagepicker module to access camera roll, select a single image, then use this image in the app.
  2. Use camera module to take a photo with option saveToGallery:true. The new photo is saved to gallery, but it seems there is no promise returned and no error thrown.

From either picker or camera, the app adds imageSource to an ObservableArray for display and base64 encodes and posts to server.

If I 1st use the camera, it works properly, then use the imagepicker which OK as well. However, the camera module will no longer work afterwards, per above hanging sequence.

If I set saveToGallery:false, then both modules work in any order, the image is just not save to camera roll.

Here is my 'tns info' & image picker/camera modules from package.json:

โ”‚ Component        โ”‚ Current version โ”‚ Latest version โ”‚ Information โ”‚
โ”‚ nativescript     โ”‚ 2.4.2           โ”‚ 2.4.2          โ”‚ Up to date  โ”‚
โ”‚ tns-core-modules โ”‚ 2.4.4           โ”‚ 2.4.4          โ”‚ Up to date  โ”‚
โ”‚ tns-android      โ”‚ 2.4.1           โ”‚ 2.4.1          โ”‚ Up to date  โ”‚
โ”‚ tns-ios          โ”‚ 2.4.0           โ”‚ 2.4.0          โ”‚ Up to date  โ”‚

    "nativescript-camera": "0.0.8",
    "nativescript-imagepicker": "^2.4.1",

App code using camera module takePicture:

    takePhoto() {
        this.drawer.toggleDrawerState();
        console.log("In takePhoto");

        // takePicture imported from "nativescript-camera"
        takePicture({
            width: 300,
            height: 300,
            keepAspectRatio: true,
            saveToGallery: false
        }).
            then((imageAsset) => {
                // When app hangs this code is not processed
                let image = new Image();
                image.src = imageAsset;
                console.log("In camera.takePicture, imageAsset.nativeImage = ");
                console.log(imageAsset.nativeImage);

                let imageAsBase64 = fromNativeSource(imageAsset.nativeImage).toBase64String("jpeg");
                this.imagesArray.unshift( { 'imgsrc':fromNativeSource(imageAsset.nativeImage), 'index':this.imagesArrayIndex } );
                this.imagesArrayIndex++;
                this.reindexImagesArray();

                this.addCaptionAndSaveToServer( imageAsBase64 );

            }).catch((err) => {
                console.log("Error -> " + err.message);
            });
    }

App code using imagepicker module"

    addExistingPhoto() {
        let context = imagepickerModule.create({
            mode: "single"
        });
        // this.selectedPhotoImgSrc = new ImageSource();
        this.drawer.toggleDrawerState();
        this.startSelection(context);
    }

    startSelection( context ) {
        context
            .authorize()
            .then(() => {
                //this.selectedPhotoArray = [];
                return context.present();
            })
            .then((selection) => {
                selection.map( selected => {
                    selected.getImage().then( v => {
                        // this.selectedPhotoImgSrc = v;
                        console.log( "In startSelection, v = " + v );
                        this.imagesArray.unshift( { 'imgsrc':v , 'index':this.imagesArrayIndex } );
                        this.imagesArrayIndex++;
                        this.reindexImagesArray();
                        let imageAsBase64 = v.toBase64String("jpeg");
                        this.addCaptionAndSaveToServer( imageAsBase64 );
                    });

                });
                // this.selectedPhotoArray = selection;
                // this._changeDetectionRef.detectChanges();
            })
            .catch(function (e) {
                console.log(e);
            });
    }

Appreciate any assistance or suggestions.

(Android) Crash when using back button to close the dialog and then open it again and take a picture

Hello,
I've just double checked in slack and forum and this problem is reproducible, here the details:

https://discourse.nativescript.org/t/problems-with-nativesckipt-camera-plugin/3006/4

Basically if after I clicked the back button to close the screen I re-execute the code to open it again, and take the picture and confirm, I get the error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3453, result=-1, data=Intent {  }} to activity {com.anygofitness.anygopartner/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onActivityResult failed

Error: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.anygofitness.anygopartner/files/NSIMG_20171101_173244.jpg (No such file or directory)
    java.io.FileInputStream.open(Native Method)
    java.io.FileInputStream.<init>(FileInputStream.java:146)
    java.io.FileInputStream.<init>(FileInputStream.java:99)
    android.media.ExifInterface.<init>(ExifInterface.java:1106)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
    com.tns.Runtime.callJSMethod(Runtime.java:957)
    com.tns.Runtime.callJSMethod(Runtime.java:941)
    com.tns.Runtime.callJSMethod(Run

This is a very important issue, please let me know if you need any other info...

Thanks,
Dem

Android: (Calling js method onScanCompleted failed) when saveToGallery is true

I'm having an issue with my Android build where if I set saveToGallery to true, after taking a picture and selecting it, rather than display it on the view, the app crashes with the following error below. But when it's set to false, the picture is taken, selected and shows up fine in my view.

An uncaught Exception occurred on "main" thread.
com.tns.NativeScriptException: 
Calling js method onScanCompleted failed

TypeError: trace.isEnabled is not a function
File: "file:///data/data/org.nativescript.kidquest/files/app/tns_modules/nativescript-camera/nativescript-camera.js, line: 63, column: 50

StackTrace: 
	Frame: function:'onScanCompleted', file:'file:///data/data/org.nativescript.camera-app/files/app/tns_modules/nativescript-camera/nativescript-camera.js', line: 63, column: 51

	at com.tns.Runtime.callJSMethodNative(Native Method)
	at com.tns.Runtime.access$2400(Runtime.java:33)
	at com.tns.Runtime$3.run(Runtime.java:1214)
	at android.os.Handler.handleCallback(Handler.java:751)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:154)
	at android.app.ActivityThread.main(ActivityThread.java:6119)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

in the logcat, I noticed this:

TNS.Native: Failed to load snapshot: dlopen failed: library "libsnapshot.so" not found

Oddly, this issue does not occur with my iOS build. Here is my source code:

import { Observable } from 'data/observable';
import { takePicture, requestPermissions } from 'nativescript-camera';
import * as imageSourceModule from "image-source";

export class CameraModel extends Observable {

    currentImage: any

    constructor() {
        super();
        requestPermissions();
    }

    takePhoto (args) {
        let self = this;
        takePicture({ width: 180, height: 180, keepAspectRatio: false, saveToGallery: true})
            .then((imageAsset) => {
                console.log("IMAGE ASSET:", imageAsset);
                let source = new imageSourceModule.ImageSource();
                source.fromAsset(imageAsset).then((source) => {
                    console.log(`Size: ${source.width}x${source.height}`);
                })
                self.set('currentImage', imageAsset);
            }, (error) => {
                console.log("Error: " + error)
            });
    }
}

Here is the main-page.ts file:

import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { CameraModel } from './main-view-model';

export function navigatingTo(args: EventData) {
  
    let page = <Page>args.object;
    page.bindingContext = new CameraModel();
}

And finally, the xml file:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">

    <Page.actionBar>
        <ActionBar title="Camera App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>

       <StackLayout class="p-20">
        <Image src="{{ currentImage }}" id="image" stretch="aspectFit" margin="10"/>
        <Button text="TAKE PHOTO" tap="{{ takePhoto }}" class="btn btn-primary btn-active"/>
    </StackLayout>
</Page>

Everything works great if saveToGallery is set to false, but not when it's set to true. Is there something I'm doing wrong?

The project was created using the tns typescript template and then I added the native-script camera plugin.

Image Orientation Issue

I just migrated my code to use this plugin instead of the "default" one and I noticed that if I take a picture in portrait orientation, then the resulting image is saved in landscape orientation, the image does not keep the portrait orientation and is is hard to look at the picture without rotating the phone, this issue is not present in the "default camera module".
if the image is taken in landscape then it keeps it that way, no issue.
Any ideas?

Thanks

Saving image to file system

I'm having problems saving the image taken with the camera to the file system.

The following test works. I'm able to create an imageSource from a local resource and save it to the file system:

var cameraModule = require("nativescript-camera");
var fs = require('file-system');
var imageSource = require("image-source");


var img = imageSource.fromResource("some_resource_that_exists");

var folder = fs.knownFolders.documents();
console.log('folder - ', folder); // => object

var path = fs.path.join(folder.path, "Test.png");
console.log('path - ', path); // => correct path

var saved = img.saveToFile(path, "png");
console.log('saved - ', saved); // => true

var imgLocal = imageSource.fromFile(path);

// ### binding to "imgLocal" works. Image is displayed
pageData.camera.set("cameraImage", imgLocal);

Yet doing the same thing with the image returned from the camera plugin fails silently at saveToFile():

var cameraModule = require("nativescript-camera");
var fs = require('file-system');
var imageSource = require("image-source");


cameraModule.takePicture({
    width: 300,
    height: 300,
    keepAspectRatio: true
}).then(function (imageAsset) {
    console.log("Image taken!");

    var img = imageAsset;

    var folder = fs.knownFolders.documents();
    console.log('folder - ', folder); // => object

    var path = fs.path.join(folder.path, "Test.png");
    console.log('path - ', path); // => correct path

    var saved = img.saveToFile(path, "png"); // ### Execution stops here.
    console.log('saved - ', saved);

    var imgLocal = imageSource.fromFile(path);

    pageData.camera.set("cameraImage", img);
});

Am I doing something incorrectly?

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Component        โ”‚ Current version       โ”‚ Latest version โ”‚ Information โ”‚
โ”‚ nativescript     โ”‚ 2.3.0                 โ”‚ 2.3.0          โ”‚ Up to date  โ”‚
โ”‚ tns-core-modules โ”‚ 2.4.0-2016-10-07-4335 โ”‚ 2.3.0          โ”‚ Up to date  โ”‚
โ”‚ tns-android      โ”‚ 2.3.0                 โ”‚ 2.3.0          โ”‚ Up to date  โ”‚
โ”‚ tns-ios          โ”‚ 2.3.0                 โ”‚ 2.3.0          โ”‚ Up to date  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Error: Uncaught (in promise): null

I insert latest nativescript-camera plugin
tns 3.2.1
typescript: 2.4.2
device htc 626

public takePicture() {
        if ( isAvailable() ){
            takePicture( { width: 300, height: 300, keepAspectRatio: false, saveToGallery: true } )
                .then(picture => {
                    console.dir(picture);
                    this.cameraImageSrc = picture;
                }).catch((err) => {
                //console.log("Error -> " + err.message);
            });
        }
    }
<Image row="1"
                           [src]="cameraImageSrc"
                           stretch="aspectFit"
                           margin="10"
                           width="200"
                           height="200"></Image>

I get this console:
Error: Uncaught (in promise): null

ActivityManager: START u0 {act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.htc.camera/.CameraServiceEntry clip={text/uri-list U:content://hu.neosoft.praktiker.provider/external_files/DCIM/Camera/NSIMG_20171016_15427.jpg} (has extras)} from uid 10268 pid 28769 on display 0

Please help me what is wrong my code?

Nativescript Camera Angular 4 Component Not Rendering

Does the camera component work in an AVD Android emulator that has one or both emulated cameras enabled and working? If so, my Angular component of the nativescript-camera doesn't render at all.. I embed my component on the home page, and it doesn't render anything.

I have tested the AVD Android emulator's camera by opening the camera app, and verifying that it runs and shows video from my laptop camera. I can give more information about the specific configuration of the AVD I'm running / deploying my app onto, but it isn't special.

My app is built on Angular Seed Advanced with the following versions in the (outer) Angular 4.

Here is my component:

import { Component, Inject } from '@angular/core';
import { takePicture, requestPermissions } from 'nativescript-camera';
import { ImageSource } from 'tns-core-modules/image-source';
import { ImageAsset } from 'tns-core-modules/image-asset';

@Component({
  selector: 'camera-cmp',
  template: 'camera.component.html'
})
export class CameraComponent {
  public saveToGallery: boolean = true;
  public cameraImage: ImageAsset;

  onTakePictureTap(args) {
    takePicture({ width: 180, height: 180, keepAspectRatio: false, saveToGallery: this.saveToGallery })
      .then((imageAsset) => {
        let source = new ImageSource();
        source.fromAsset(imageAsset).then((source) => {
          console.log(`Size: ${source.width}x${source.height}`);
        });
        this.cameraImage = imageAsset;
      }, (error) => {
        console.log('Error: ' + error);
      });
  }

  onRequestPermissionsTap() {
    requestPermissions();
  }
}

Here is the template:

<GridLayout rows="auto, *, auto">
  <StackLayout orientation="horizontal" row="0" padding="10">
    <Label text="saveToGallery"></Label>
    <Switch [(ngModel)]="saveToGallery"></Switch>
  </StackLayout>
  <Image row="1" [src]="cameraImage" stretch="aspectFit" margin="10"></Image>
  <StackLayout orientation="horizontal" row="2" padding="10">
    <Button text="Take Picture" (tap)='onTakePictureTap($event)'></Button>
    <Button text="Request Permissions" (tap)='onRequestPermissionsTap()'></Button>
  </StackLayout>
</GridLayout>

Here are my versions of things:

$ tns plugin
Dependencies:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Plugin                     โ”‚ Version โ”‚
โ”‚ @angular/animations        โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/common            โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/compiler          โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/core              โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/forms             โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/http              โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/platform-browser  โ”‚ ~4.1.2  โ”‚
โ”‚ @angular/router            โ”‚ ~4.1.2  โ”‚
โ”‚ @ngrx/core                 โ”‚ ^1.2.0  โ”‚
โ”‚ @ngrx/effects              โ”‚ ^2.0.3  โ”‚
โ”‚ @ngrx/store                โ”‚ ^2.2.2  โ”‚
โ”‚ @ngx-translate/core        โ”‚ ^6.0.1  โ”‚
โ”‚ @ngx-translate/http-loader โ”‚ 0.0.3   โ”‚
โ”‚ angulartics2               โ”‚ ^2.2.1  โ”‚
โ”‚ lodash                     โ”‚ ^4.17.4 โ”‚
โ”‚ nativescript-angular       โ”‚ ~3.1.0  โ”‚
โ”‚ nativescript-camera        โ”‚ ^3.0.0  โ”‚
โ”‚ nativescript-localstorage  โ”‚ ^1.1.2  โ”‚
โ”‚ nativescript-theme-core    โ”‚ ^1.0.4  โ”‚
โ”‚ ngrx-store-freeze          โ”‚ 0.1.9   โ”‚
โ”‚ reflect-metadata           โ”‚ ^0.1.8  โ”‚
โ”‚ rxjs                       โ”‚ ^5.4.0  โ”‚
โ”‚ tns-core-modules           โ”‚ ~3.1.0  โ”‚
โ”‚ zone.js                    โ”‚ ^0.8.10 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Dev Dependencies:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Plugin                            โ”‚ Version โ”‚
โ”‚ @angular/compiler-cli             โ”‚ ~4.1.2  โ”‚
โ”‚ @ngrx/store-devtools              โ”‚ ~3.2.4  โ”‚
โ”‚ @ngtools/webpack                  โ”‚ 1.3.1   โ”‚
โ”‚ @types/jasmine                    โ”‚ 2.5.41  โ”‚
โ”‚ @types/lodash                     โ”‚ 4.14.63 โ”‚
โ”‚ babel-traverse                    โ”‚ 6.11.4  โ”‚
โ”‚ babel-types                       โ”‚ 6.11.1  โ”‚
โ”‚ babylon                           โ”‚ 6.8.4   โ”‚
โ”‚ codelyzer                         โ”‚ ^3.0.1  โ”‚
โ”‚ copy-webpack-plugin               โ”‚ ~4.0.1  โ”‚
โ”‚ extract-text-webpack-plugin       โ”‚ ~2.1.0  โ”‚
โ”‚ fs-extra                          โ”‚ ^0.30.0 โ”‚
โ”‚ glob                              โ”‚ ^7.0.5  โ”‚
โ”‚ lazy                              โ”‚ 1.0.11  โ”‚
โ”‚ nativescript-css-loader           โ”‚ ~0.26.0 โ”‚
โ”‚ nativescript-dev-android-snapshot โ”‚ ^0.0.9  โ”‚
โ”‚ nativescript-dev-sass             โ”‚ ^1.1.1  โ”‚
โ”‚ nativescript-dev-webpack          โ”‚ ^0.5.0  โ”‚
โ”‚ opener                            โ”‚ ^1.4.1  โ”‚
โ”‚ raw-loader                        โ”‚ ~0.5.1  โ”‚
โ”‚ resolve-url-loader                โ”‚ ~2.0.2  โ”‚
โ”‚ rimraf                            โ”‚ ^2.5.3  โ”‚
โ”‚ tar.gz                            โ”‚ ^1.0.5  โ”‚
โ”‚ tns-platform-declarations         โ”‚ ^3.0.1  โ”‚
โ”‚ tslint                            โ”‚ ^5.2.0  โ”‚
โ”‚ typescript                        โ”‚ ~2.3.2  โ”‚
โ”‚ webpack                           โ”‚ ~2.5.1  โ”‚
โ”‚ webpack-sources                   โ”‚ ~0.2.3  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

I carefully followed and integrated the pertinent the CameraTestAngular code, into my all the way up to date Angular Seed Advanced source tree, because the CameraTestAngular app fails to run because:

$ tns run android --device AVD_for_my_android
Executing before-prepare hook from /Volumes/share/projects/nativescript-camera/examples/CameraTest/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.4.1
node_modules/tns-core-modules/ui/core/properties/properties.d.ts(48,14): error TS2559: Type 'Property<T, U>' has no properties in common with type 'TypedPropertyDescriptor<U>'.

node_modules/tns-core-modules/ui/core/properties/properties.d.ts(59,14): error TS2559: Type 'CoercibleProperty<T, U>' has no properties in common with type 'TypedPropertyDescriptor<U>'.

TypeScript compiler failed with exit code 1

(and the npm start script that the README.md says to use apparently doesn't exist.

Let me know if you need to see any other files in my source tree.

Support for custom preview

Does this plugin support custom camera preview?
where we can show the selected portion of image in some blue color line ?

Is it something like while scanning QR code some apps open square selection area for picture.

checkSelfPermission is not function

From @damon-yang on August 28, 2017 3:32

nativescript-camera . module
error:
image

code:

var isAvailable = camera.isAvailable();
    console.log(isAvailable)
    if (isAvailable) {
        var imageModule = require("ui/image");
        camera.takePicture()
            .then(function(imageAsset) {
                console.log("Result is an image asset instance");
                var image = new imageModule.Image();
                image.src = imageAsset;
            }).catch(function(err) {
                console.log("Error -> " + err.message);
            });
    }

image

Copied from original issue: NativeScript/docs#888

Ability to check the status of the requested permissions.

Why does the requestPermissions method return void and not the result of the request? How are we supposed to handle the case where the user denies permission to use the camera? I can see in the code for iOS you catch the permission denied case and log it, while in Android the result is never even checked. In both cases nothing is returned to the calling code, which does not make sense to me. Am I missing something?

Camera permissions are ignored?

Currently my AndroidManifest.xml is :

    ...
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    ...

Now - When I'm using :

   camera.takePicture({
                width:           400,
                height:          400,
                keepAspectRatio: true,
                saveToGallery:   false
            })

I get an error :

JS: Error -> Application does not have permissions to use Camera

But If I prepend this code :

  camera.requestPermissions();

Then I see the permission dialog and when approved , it does uses the camera

Question

I explicitly declared camera permission in the manifest.
So why is it ignored ? What should I change in order for the permission in manifest to be respected ?
Showing the user a permission dialog each time - is very nonprofessional.

Set image path

I looked into code and verified the image path is generated based on timestamp is it possible to give an path to image file?

module fails on NS2.1.6 Samsung Gs7, it doesn`t fire onActivityResult

I believe it would work if do the following:

  1. Add: var _activity = appModule.android.foregroundActivity || appModule.android.startActivity;
    1.1. Substitute: appModule.android.onActivityResult = (requestCode: number, resultCode: number, data: android.content.Intent) => {
    onto
    _activity.onActivityResult = (requestCode: number, resultCode: number, data: android.content.Intent) => {
    1.2 Substitute:
    appModule.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    onto

_activity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);

v3.1.3 Doesn't have the latest code changes on npmjs

For v3.1.3 release, the code changes which were made, like handling the back button press,
fixing crash after canceling taking an image and trying to capture again, are not a part of v3.1.3 release. The js which is there in that package still contains old code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.