capacitor barcode scan
If you npm install a Cordova/Capacitor plugin after npx cap add android then make sure you run npx cap update before running from Android Studio again.
If you make html, js, ts, css changes, run ionic build again and also run npx cap copy.
Or when in doubt, run npx cap sync as it does update+copy.
https://github.com/ionic-team/capacitor/issues/1213
https://stackoverflow.com/questions/23060038/cant-use-barcode-scanner-in-cordova-plugin-is-installed
1. init
npx @capacitor/cli create testbarcode
npx cap add android
npx cap sync
npx cap copy
npx cap open android
ctrl+c exit
2. npm i phonegap-plugin-barcodescanner
npm i phonegap-plugin-barcodescanner --save
npx cap sync
npx cap copy
3. modify www/index.html
ADD
<button onclick="myFunction2()">Try it barcode</button>
<script>
async function myFunction2() {
cordova.plugins.barcodeScanner.scan(
result => console.log(result),
err => console.error(err),
{
showTorchButton: true,
prompt: "Scan your code",
formats: "QR_CODE",
resultDisplayDuration: 0
}
);
}
</script>
npx cap sync
npx cap copy
android studio run