Android二维码/条形码扫码,barcodescanner

2018-01-13 11:05:24来源:网络收集作者:管理员人点击

分享

阿里云爆款

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();
}
}


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台