QRCode - Zxing plugin


#1

@NathanaelA
Since your the owner of the plugin i identified you.
https://www.npmjs.com/package/nativescript-zxing

I am trying to create a QR CODE (not a barcode, a QR CODE) from a string.
Then i want to save this QR CODE to a app_resources
Then show the QR CODE on my application.
So far i got this:

      var ZXing = require('nativescript-zxing');
        var imageSource = require('image-source');
        var fs = require('file-system');
        var utils = require('utils/utils');
        var zx = new ZXing();
 


                var imageSource = require("image-source");
        
                var img = zx.createBarcode({ encode: "Text", height: 100, width: 100, format: ZXing.QR_CODE });
        
                var folder = fs.knownFolders.documents();
                console.log('folder - ', folder); // => object
        
                var path = fs.path.join(folder.path, "Test.png");
                console.log('path - ', path); // => Not redirecting to app_resources how do i do it?
        
                var saved = img.saveToFile(path, "png");
                console.log('saved - ', saved); // => img.saveToFile is not a function
        
                var imgLocal = imageSource.fromFile(path);

But it gives me an error input on

                var saved = img.saveToFile(path, "png");
                console.log('saved - ', saved); // => img.saveToFile is not a function

I searched online and it says to use ImageAsset to prevent this, but i have no clue on how to do it.


#2

Check the demo. I’m pretty sure I save the image in the demo…

Nathanael A.


#3

According to your demo you have the function to save the demo, which i already investigated and tried on my own code.


But when it comes to this line of code
folder = android.os.Environment.getExternalStoragePublicDirectory (android.os.Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/";
it gives me input errors on this keyword " on" .


#4

I don’t see an “on” in the source code. Where is it breaking?

Nathanael A.


#5

@NathanaelA
right there on the 4th line of code.

folder = android.os.Environment


#6

Do you mean “os”? If so that is correct, “os” is a valid property off of android. Please try building the demo project in the repo and verify it works for you. If your own code is breaking that is a configuration issue with your code, not an issue with my code. :wink:

Nathanael A.


#7

Sorry for my rusty english i did not ment to say there was an issue with your code, far from that.

That plugin only works if i want to create a barCode?

Is it possible to create a QR Code from a string and display on screen with that plugin?
If so, how? having troubles on how to figure this out and i really need this to proceed on my work :frowning:


#8

The plugin itself does not display a image; however, you can use the Image component that is built into NativeScript to show the image. Check the demo out to see how to easily do that.

Nathanael A.


#9

@NathanaelA
I keep trying to use your demo in order to use the Image Component to build a QR Code from a String, but i still can’t achieve the desired result.

My code so far:

        var ZXing = require('nativescript-zxing');
        var imageSource = require('image-source');
        var fs = require('file-system');
        var utils = require('utils/utils');
        var zx = new ZXing();



        let currentAppFolder = fs.knownFolders.currentApp();
        console.log(currentAppFolder);
        let currentApp = fs.path.normalize(currentAppFolder.path);
        console.log(currentApp);


        var imageSource = require("image-source");

        var img = zx.createBarcode({ encode: "Text", height: 100, width: 100, format: ZXing.QR_CODE });

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

        var path = fs.path.join(currentAppFolder.path, "Test.png");
        console.log('path - ', path); // => Not redirecting to app_resources
        let source = new imageSource.ImageSource();
        var saved = source.saveToFile(path, "png");
        console.log(source.saveToFile(path, "png"));
        console.log('saved - ', saved); // => img.saveToFile is not a function

#10

@NathanaelA i Keep trying and i am still stuck in the QR Code from a String. Could you provide me some further hints?

Thank you, best regards


#11

No one used this plugin yet that could help me?


#12

Solved this issue thanks!


#13

Hello PurpleRune,

Could you indicate how you solved the issue? What did you do to have it create QR codes?


#14

@jessiPP

Ok so i was using typescript with angular and one thing to be aware is of the function calls. I basically moved my code inside ngOnInit function and it started working cause he knew where to grab the files.

I’ll be back on my company monday morning and i can re-check my code and give you more hints on how to overcome your problem if you need help. I know that my answer is very ambigous but i dont have really remenber what was causing my issue, i am just trying to remenber. But i will gladly be willing to help you if you need more help!