源码简介
Zxing扫描码的实例。程序中有少许BUG,长时间未扫描会出现假死的状况。
源码运行截图
源码片段:
- public class MainActivity extends Activity{
- private Button button;
- private TextView resultText;
- private final static int SCANNIN_GREQUEST_CODE = 1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- resultText = (TextView) this.findViewById(R.id.result);
- button = (Button) this.findViewById(R.id.scanCodeButton);
- button.setOnClickListener(new OnClickListener(){
- @Override
- public void onClick(View v) {
- Intent intent = new Intent();
- intent.setClass(MainActivity.this, CaptureActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- switch(requestCode){
- case SCANNIN_GREQUEST_CODE:
- if(resultCode == RESULT_OK){
- Bundle bundle = data.getBundleExtra("bundle");
- String resultString = bundle.getString("result");
- resultText.setText(resultString);
- }
- break;
- }
- }
- }
源码链接:http://down.51cto.com/data/1983052