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
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.
来源:https://stackoverflow.com/questions/11558574/a-qr-scanner-inside-of-a-fragment