当前位置:编程学习 > wap >>

二维码扫描的运用

public void PressTrsSaoMiao()
    {
     PressSaoMiao=(Button)this.findViewById(R.id.saomiaobtn);
     PressSaoMiao.setOnClickListener(new OnClickListener()
      {
     public void onClick(View v)
     {
    Intent mIntent = new Intent();
            ComponentName comp = new ComponentName("com.google.zxing.client.android",
            "com.google.zxing.client.android.CaptureActivity");
            mIntent.setComponent(comp);
            mIntent.setAction("android.intent.action.MAIN");
       
            startActivity(mIntent);
     } 
      });
    } 

为什么调用不到二维码的扫描程序 --------------------编程问答-------------------- 二维码的应用是越来越广呢。我们会收到在手机上扫描二维码的需求,那么,我们尝试使用一种方法实现。

 

前置: 

需要第三方APK。名称是 “条码扫描器” ,该APK在 google play 和豌豆荚市场都能够下载到。

过程:

1,开始扫描二维码

IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);//指定当前的activity

integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES); //启动扫描

2,注册扫描完成后的处理(回调)

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {

IntentResult result = IntentIntegrator.parseActivityResult(requestCode,

resultCode, intent);

if (result != null) {

String contents = result.getContents();

if (contents != null) {

showDialog(R.string.result_succeeded, result.toString());

} else {

showDialog(R.string.result_failed,

getString(R.string.result_failed_why));

}

}

}

3,完成。。。

那么我们需要上面提到的类 IntentIntegrator  ,从哪里来的? 我是从 google开源的项目zxing里代码里找到的。并提取了一些代码来使用。我会在本文的末尾提供代码下载,可以从代码里获得这个类。
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,