Scanning QR or Barcode is among the commonest use circumstances on cell apps. Since QR/Barcode direct scanning requires the digicam’s dwell feed, the digicam permission must be requested.
Now the query is can we keep away from asking for digicam permission and nonetheless obtain the identical use case?
The shortest reply to this query is YES.
Google Code Scanner
It offers an entire answer for scanning codes with out requiring your app to ask permission from the digicam. This additional will increase person privateness because the app no longer asks for digicam permissions and thus will not have entry to the digicam.
The way it works?
Because the app no longer asks for digicam permissions, it isn’t potential to scan the code within the app by opening the interface with CameraX, so what to do now?
Nicely, Google Code Scanner is nicely outlined for a really particular use case of code scanning and it would not do something however that, so leveraging Google Play Providers to realize this activity is sort of actuality. So it delegates the duty of scanning the code to Google Play companies and solely returns the scan outcomes to the app.
How about safety?
All picture processing takes place on the gadget, and Google doesn’t retailer the outcomes or picture information. As well as, the app no longer asks for digicam permissions simply to scan the code, so it offers customers confidence when utilizing the app.
When ought to I exploit it?
Because it delegates scanning to Google Play Providers, it’s impractical to alter the interface supplied by the service, so if the requirement is to scan solely with none customized UI then this is usually a nice choice.
Please add Google Code Scanner
Add mavenCentral() set up.gradle
Add code scanner dependency construct.gradle
Add metadata to clear file in order that Google Play companies mechanically downloads the scanner module to your gadget whereas your app is put in from the Play Retailer. In case you do not add it to the metadata it should obtain the scanner module the primary time it’s used.
In case you already know in regards to the codecs the applying will scan then you possibly can present these as setBarcodeFormats which could be very helpful to hurry up scanning.
Lastly, create the scanner object by specifying the context and choices (or simply the context) for GmsBarcodeScanning after which use this object to scan the code as follows
Every time the scan is profitable, it should set off the addOnSuccessListener which is able to present the barcode object. You will discover the kind of QR code or barcode and browse its worth by calling “barcode.rawValue”
Including such form of scanning is so simple as including the lib and calling startScan(), additionally as a result of it delegates the scanning to Google Play Providers, so it will not have an effect on the app measurement a lot.