-
Notifications
You must be signed in to change notification settings - Fork 177
need help to use barcode scanner #26
Comments
You need to hide every element on your document. .scanner-ui { display: none; }
.scanner-hide { visibility: visible; }
body.qrscanner { background-color: transparent; }
body.qrscanner .scanner-ui { display: block; }
body.qrscanner .scanner-hide { visibility: hidden; } I made the scanner interface inside a div with App Component HTML: <ion-app class="scanner-hide">
...App View
</ion-app>
<div class="scanner-ui">
...Scanner Interface
</div> When the scanner is open i added the To add or remove the //ADD
document.body.classList.add("qrscanner");
//REMOVE
document.body.classList.remove("qrscanner"); |
Thanks @tripodsgames! I tried out your clever way to show/hide the ionic pages that may block the barcode camera view.
|
You need to call this in the Javascript BarcodeScanner.hideBackground(); // make background of WebView transparent
document.body.classList.add("qrscanner"); // add the qrscanner class to body
const result = await BarcodeScanner.startScan(); // startscan
document.body.classList.remove("qrscanner"); // remove the qrscanner from the body Also put the css at the bottom of global.scss file |
Your help is superb @tripodsgames! you saved me from the middle of the sea 😁😎 For those who are newbies trying out this plugin, on top of the Ionic/Angular tutorial. The detailed steps:
Edit tutorial-photo-gallery-angular/android/app/src/main/java/io/ionic/pg/ng/cap/MainActivity.java, add lines as indicated. package io.ionic.pg.ng.cap;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import java.util.ArrayList;
// add this line
import com.dutchconcepts.capacitor.barcodescanner.BarcodeScanner;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Add this line
add(BarcodeScanner.class);
}});
}
} Edit android/app/src/main/AndroidManifest.xml according, add the lines indicated by leading "+" <manifest
+ xmlns:tools="http://schemas.android.com/tools"
package="io.ionic.pg.ng.cap">
<application
+ android:hardwareAccelerated="true"
</application>
+ <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
</manifest>
.scanner-ui { display: none; }
.scanner-hide { visibility: visible; }
body.qrscanner { background-color: transparent; }
body.qrscanner .scanner-ui { display: block; }
body.qrscanner .scanner-hide { visibility: hidden; }
<ion-app class="scanner-hide">
<ion-router-outlet></ion-router-outlet>
</ion-app>
<div class="scanner-ui">
...Scanner Interface
</div>
// add a function to trigger barcode scanning
public async startScan() {
// const { BarcodeScanner } = Plugins;
BarcodeScanner.hideBackground(); // make background of WebView transparent
document.body.classList.add("qrscanner"); // add the qrscanner class to body
const result = await BarcodeScanner.startScan(); // startscan
document.body.classList.remove("qrscanner"); // remove the qrscanner from the body
// if the result has content
if (result.hasContent) {
console.log(`barcode scanning result=${result.content}`); // log the raw scanned content
}
}
<ion-fab vertical="top" horizontal="center" slot="fixed">
<ion-fab-button (click)="photoService.startScan()">
<ion-icon name="camera"></ion-icon>
</ion-fab-button>
</ion-fab>
Hope the above would provide some hints in getting started to use capacitorjs. |
Thanks for all the help guys. Will take a look if I can put this in the docs somewhere. |
I am doing everything of the above.
global.scss:
thx for your help! |
You need to create your own camera overlay using css and html inside the scanner-ui div. |
@jw-redpanda I honestly appreciate all your effort. I'm convinced that your endeavour to improve the community's understanding was very beneficial from some developers' perspectives. Anyway, maybe you would like to have another go with your approach. Regards, Peter |
https://www.youtube.com/watch?v=8GXfjDUCYjU |
Closing this issue since the docs are a little more elaborate now and also references this issue and #7 |
Thanks @tripodsgames , this works great! Since we are hiding the whole
|
You have to find a way to blur the parent element without affecting the child. |
This worked perfectly for me https://github.com/Nykz/Ionic-6-qrcode |
I am new to capacitorjs and trying out your plugin BarcodeScanner.
Followed the instructions, defining build.gradle, adding BarcodeScanner.class in MainActivity.
Also, run 'ionic build; ionic cap copy; ionic cap sync' and then re-compile and run on Android device.
In the Ionic App, I have a service providing startScan() function that will be trigger by a user click:
However, it seems it has no function at all. After clicked and called the function, it has no scanning window popped. Can anyone help to give me some hints? Thanks.
The text was updated successfully, but these errors were encountered: