Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A QR scanner inside of a Fragment

I'm using ViewPager for swiping between my Fragments. Is it possible to integrate a QR scanner (zxing or any other) inside of a Fragment so that I can swipe from scanners View to another Fragment and vice versa?

As far as I can tell, the majority of qr scanners require me to use an extended Activity class and to start it for result, handling it in onActivityResult, which is not an option to me

like image 434
Nikolay Arhipov Avatar asked Jul 19 '12 10:07

Nikolay Arhipov


People also ask

How do QR codes work internally?

A QR code works similarly to barcodes at the supermarket. Each QR code consists black squares and dots which represent different pieces of information. When scanned, the unique pattern on the barcode translates into human-readable data. This transaction happens in seconds.

What part of a QR code gets scanned?

The QR code scanner begins at the bottom right of the QR code. It then moves up two data modules at a time until it hits the first position marker. Then it moves two data modules to the left and goes down.

What is embedded QR code?

The embedded authentication data contains a message authentication code or the cryptographic signature of the encoded data. It is being embedded into the QR code by taking advantages of the barcode redundancy. The printed stego QR code is first captured by a mobile phone camera or a barcode scanner.


1 Answers

The barcodefragmentlib is the one you are looking for. And its wiki shows you how to integrate it (although I used a different way before the wiki comes out).

However after fully integrated it and solve all the issues for our commercial app, I feel like put a QR scanner inside a fragment and switch using ViewPager is not a good idea. Some of the known issues with this idea and the mentioned library to me are:

  • Frequently switch between the QR fragment and other fragments will make your app laggy and easy to crash;
  • Fragment replacement is not so easy to handle as Activity, QR fragment is even worse;
  • Handling portrait/horizontal scan mode is not available by default (related to original ZXing lib)
  • When first open the QR fragment, it may black out your screen for a very short time
  • Scanner is not working well on Galaxy S4 or other new devices with higher resolution camera/display

Although these issues mentioned above can be solved with certain effort, it is really a trade off.

like image 165
Felixqk Avatar answered Sep 30 '22 00:09

Felixqk