android 条码识别软件开发全解析(续1详解)

http://www.cnblogs.com/tankaixiong/archive/2010/10/28/1863997.html

前天我发了一篇关于android开发条码识别软件应用程序的博客,没想到竟很受关注。

我也挺受鼓舞的,好吧,我接上次的博客继续往下写。

前篇有人讲我写的没有实质内容,我接受建议,这里我就带大家体验一下最简单最直接的完美体验。

编写你的第一个android条码识别程序。zxing的简单使用!

第一步:下载zxing组件:我上篇也简单介绍了一下这个组件,这里也不啰嗦了。

下载两个东东

源码和文档说明:

地址下如

http://code.google.com/p/zxing/downloads/detail?name=ZXing-1.6.zip&can=2&q=

BarcodeScanner3.5.apk这个是编译好的一个可安装的apk程序!这个后面将用到。

地址如下

http://code.google.com/p/zxing/downloads/detail?name=BarcodeScanner3.51b1.apk&can=2&q=

第二步:
模拟器已完全打开后
安装BarcodeScanner3.5.apk

cmd中cd 到sdk目录

利用adb命令安装BarcodeScanner3.5.apk

adb install BarcodeScanner3.5.apk 所在目录,请确定安装成功了。

第三步:ok 终于到编码了!

代码



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MyTest extends Activity {
/** Called when the activity is first created. */
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.mytest);

tv=(TextView) findViewById(R.id.mytxt);
findViewById(R.id.mybtn).setOnClickListener(listener);
}
public Button.OnClickListener listener=new Button.OnClickListener(){
public void onClick(View v){


Intent intent = new Intent("com.google.zxing.client.android.SCAN");//调用扫描的actity,这里其实只是转到刚才安装的BarcodeScanner3程序的中一个actity
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");//输入参数,(扫描类型,..二维码)
startActivityForResult(intent, 0);//启动intent
}
};


//扫描成功后回调函数,传回code
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan

tv.setText(" 条形码为:"+contents+" 条码类型为: "+format);//利用页面的textveiw显示扫描后的结果

} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
tv.setText(" 扫描失败!");
}
}
}
}

对应的xml如下

view sourceprint?

01
<?xml version="1.0" encoding="utf-8"?>

02
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

03
android:orientation="vertical" android:layout_width="fill_parent"

04
android:layout_height="fill_parent">

05
<TextView android:layout_width="fill_parent"

06
android:layout_height="wrap_content" android:text="@string/hello"

07
android:id="@+id/mytxt" />

08

09
<Button android:text="点我开始扫描" android:id="@+id/mybtn"

10
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

11
</LinearLayout>

第三步:OK我们赶快看看效果吧, 运行。
你会看到如下:


模拟器当然没有摄像头设备是扫描不到结果的。
总结:
这里只是做了一个简单的调用,调用简单但有一个很大的缺陷,这里我们要安装两个程序!

在安装BarcodeScanner3.5.apk为前题,这明显不能接受!所以接下来我将在下篇博客继续深入。敬请关注!

更多相关文章

  1. android模拟器无法启动问题之中文路径
  2. android适配不同分辨率的手机
  3. Android开发者必备的十大开发工具[图文]
  4. android启动--深入理解启动HOME
  5. Android(安卓)渗透测试学习手册 第六章 玩转 SQLite
  6. Android获取应用程序信息——PackageManager的基本使用
  7. Android应用程序发送广播(sendBroadcast)的过程分析
  8. android 源码总体结构
  9. android 退出整个程序

随机推荐

  1. android中根据控件宽度,实现展示文本内容,
  2. Android(安卓)uevent
  3. Android Studio(二)从Eclipse的迁移到And
  4. Android 判断某一个类是否存在任务栈里面
  5. OkHttp3.0 添加SSL证书信任
  6. 浅析安卓的启动过程
  7. android 学习笔记2——实现基本功能
  8. Android工程手动增加插件包方法
  9. Android消息机制(基于源码解析)
  10. android中使用URL Scheme方式启动app