Android二维码/条形码扫码,barcodescanner
github上的开源项目:https://github.com/dm77/barcodescanner
引用:
compile 'me.dm7.barcodescanner:zxing:1.9.8'
代码:
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; import com.google.zxing.Result; import me.dm7.barcodescanner.zxing.ZXingScannerView; public class MainActivity extends AppCompatActivity { private ZXingScannerView mScannerView; private ZXingScannerView.ResultHandler mResultHandler = new ZXingScannerView.ResultHandler() { @Override public void handleResult(Result result) { Toast.makeText(getApplicationContext(), "内容:" + result.getText() + ",格式=" + result.getBarcodeFormat().toString(), Toast.LENGTH_SHORT).show(); mScannerView.resumeCameraPreview(mResultHandler); //重新开始扫码。 } }; @Override public void onCreate(Bundle state) { super.onCreate(state); mScannerView = new ZXingScannerView(this); setContentView(mScannerView); mScannerView.setResultHandler(mResultHandler); } @Override public void onResume() { super.onResume(); mScannerView.startCamera(); } @Override public void onPause() { super.onPause(); mScannerView.stopCamera(); } }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/3116.html