A QR scanner inside of a Fragment

笑着哭i 提交于 2019-11-30 01:37:26

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!