Android 二維碼掃描工具 QRCodeReaderView
阿新 • • 發佈:2019-02-17
QRCodeReaderView 是基於 ZXING 條形碼掃描工具專案改進,為了在肖像模式和增強現實目的下進行更簡單的 Android 二維碼檢測。此專案可以在相機的預覽中顯示是否有二維碼。
用法:
- Create an Activity which implements onQRCodeReadListener, and let implements required methods
- Make sure Activity orientation is PORTRAIT and give Camera permision in the manifest.xml
- Add a "QRCodeReaderView" in the layout editor like you actually do with a button for example
<com.dlazaro66.qrcodereaderview.QRCodeReaderView android:id="@+id/qrdecoderview" android:layout_width="match_parent" android:layout_height="match_parent" />
- In your onCreate method, you can find the view as usual, using findViewById() function.
- Set onQRCodeReadListener to the QRCodeReaderView.
- Start & Stop camera preview in onPause() and onResume() overriden methods.
- Use onQRCodeReadListener callbacks as you want.
- You can place widgets or views over QRDecoderView
public class DecoderActivity extends Activity implements OnQRCodeReadListener { private TextView myTextView; private QRCodeReaderView mydecoderview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_decoder); mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview); mydecoderview.setOnQRCodeReadListener(this); myTextView = (TextView) findViewById(R.id.exampleTextView); } // Called when a QR is decoded // "text" : the text encoded in QR // "points" : points where QR control points are placed @Override public void onQRCodeRead(String text, PointF[] points) { myTextView.setText(text); } // Called when your device have no camera @Override public void cameraNotFound() { } // Called when there's no QR codes in the camera preview image @Override public void QRCodeNotFoundOnCamImage() { } @Override protected void onResume() { super.onResume(); mydecoderview.getCameraManager().startPreview(); } @Override protected void onPause() { super.onPause(); mydecoderview.getCameraManager().stopPreview(); } }