Notice: The Monaca & Onsen UI Community Forum is shutting down.
For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.
Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.
Barcode scanner and REST API
-
Hi!
I think it’s a common problem but I really cannot find a solution searching on the www.
Does anyone have tried to use barcode scanner and send the informations cathced to a REST API in the same application?
I’ve tried using HTTPS and HTTP REST servers, in HTTP case I’ve changed config.xml to make it work but that change seems not compatible with barcode scanner plugin: barcode scanner always crashes after i’ve allowed it to access camera.
Barcode scanner default example works alone, REST API send data works alone, but they don’t work together: when put them together REST send works but camera access crashes. Is it so for all You too?I’ve also tried using websocket, but it seems online emulator doesn’t support it…
This is code I’ve used to send data:sendData = function () { const get = async () => { const response = await fetch(URLtoRESTapi, { method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify(dataToSend) } ); const json = await response.json();//my REST API returns {"response": "Ok"} ons.notification.alert(json.result); } get(); }
This is what I have modified in config.xml in
<platform name="android">
section.<edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge"> <application android:usesCleartextTraffic="true" /> </edit-config>
and this is my change at the top of config.xml:
<widget xmlns:android="http://schemas.android.com/apk/res/android">
I’ve used the defautl example for barcode scanner.
Thank you in advance!
Stefano