Frequently Asked Question
How to handle Camera and Barcode reader on C-five
Last Updated a year ago
Problem descriptionC-five contains only one video port that is used by both camera device and barcode reader. To ensure a good user experience, System Services app is keeping barcode reader opened. This allow the service to be reactive when user wants to scan a barcode.
Problem occurs when camera needs to be used. Using preinstalled camera app of C-five will stop barcode service at startup. So you can use both, but when an other app wants to use camera device, then it needs to stop barcode service first.
Ways of resolutionHere are some ways of resolution depending on situation you are. Please note than since Barcode Settings 3.4.0, you can start and stop barcode service manually from this app.
Default camera app is used:This case is handled, so there is nothing to do and everything should work as expected. Barcode scanner will not trig when camera app is running in foreground.
Camera is used by a web app:You should uncheck "Keep barcode reader opened" option from "General" section in Barcode Settings app. This will close barcode reader after each scan. Drawback is that user experience will be affected. There will be 200ms of latency when triggering a scan but camera can be used every time device is not scanning.
Camera is used by a another app than default:Same solution than above
Camera is used by a developer in an app:An intent shall be sent to stop barcode service. Stop barcode service before using camera, and start it again when you are done.
implementation "fr.coppernic.sdk.barcode:CpcBarcode:$barcode"Checkout last version of CpcBarcode here : https://artifactory.coppernic.fr/artifactory/webapp/#/artifacts/browse/tree/General/libs-release-coppernic/fr/coppernic/sdk/barcode/CpcBarcode
Then in your code
BarcodeReader.ServiceManager.startService(context); BarcodeReader.ServiceManager.stopService(context);If you do not want to depends on CpcBarcode :
Intent intent = new Intent(); //String pack = CpcOs.getSystemServicePackage(context); // You can use this if you depends on CpcUtilsLib or CpcCore from 1.8.9 String pack = "fr.coppernic.service.cfive"; intent.setPackage(pack); //String barcodeClass = CpcDefinitions.INTENT_SERVICE_BARCODE_CLASS; String barcodeClass = "fr.coppernic.service.barcode.CpcBarcodeService"; intent.setComponent(new ComponentName(pack, barcodeClass)); //Use one of the following to stop service intent.setAction(CpcDefinitions.INTENT_ACTION_STOP_BARCODE_SERVICE); intent.setAction("fr.coppernic.intent.action.stop.barcode.service"); //Use one of the following to start service intent.setAction(CpcDefinitions.INTENT_ACTION_START_BARCODE_SERVICE);
To go furtherhttps://github.com/Coppernic/BarcodeSample