i have 2 fragments
, in 1 of them want have qrcode scanner (using zxingscannerview
). however, camera doesn't start , can see black screen. here implementation:
qrcodereaderfragment.java
private zxingscannerview mscannerview; private linearlayout qrcameralayout; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view fragmentview = inflater.inflate(r.layout.fragment_qr_code_reader, container, false); qrcameralayout = (linearlayout) fragmentview.findviewbyid(r.id.ll_qrcamera); mscannerview = new zxingscannerview(getactivity().getapplicationcontext()); mscannerview.setlayoutparams(new linearlayout.layoutparams( linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent)); qrcameralayout.addview(mscannerview); return fragmentview; }
fragment_qr_code_reader.xml
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.letsguang.android.shoppingmalltenant.fragment.qrcodereaderfragment" android:id="@+id/fl_qrcamera" > <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/ll_qrcamera" android:orientation="vertical"> </linearlayout> </framelayout>
you didn't setup view. according documentation https://github.com/dm77/barcodescanner you've got start/stop camera in onresume/onpause:
@override public void onresume() { super.onresume(); mscannerview.setresulthandler(this); mscannerview.startcamera(); } @override public void onpause() { super.onpause(); mscannerview.stopcamera(); }
Comments
Post a Comment