Android开发_ZXing库二维码应用
2015-03-30 10:34
288 查看
Android二维码扫描应用
ZXing库精简版的下载:http://download.csdn.net/detail/a874508605/8546185
布局文件的编写
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/scan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="开始扫描二维码" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="show" />
</LinearLayout>在AndroidManifest.xml文件中声明相应的Activity
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />相应实现的源码
<span style="font-size:14px;">public class MainActivity extends Activity {
private Button scanButton;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanButton = (Button) findViewById(R.id.scan);
text = (TextView) findViewById(R.id.text);
scanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "你写可以扫描条形码或者二维码", Toast.LENGTH_SHORT).show();
Intent startScan = new Intent(MainActivity.this, CaptureActivity.class);
startActivityForResult(startScan, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resu
4000
ltCode, data);
if (resultCode == RESULT_OK) {
String result = data.getExtras().getString("result");
text.setText(result);
}
}
</span><span style="font-size:14px;">}</span>
Android生成二维码应用
相应实现的源码
public class MainActivity extends Activity {
private EditText input;
private Button genButton;
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input = (EditText) findViewById(R.id.input);
genButton = (Button) findViewById(R.id.gen);
img = (ImageView) findViewById(R.id.img);
genButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String in = input.getText().toString();
if(in.equals("")){
Toast.makeText(MainActivity.this, "请输入文本", Toast.LENGTH_SHORT).show();
}else {
try {
Bitmap qrcode = EncodingHandler.createQRCode(in, 400);
img.setImageBitmap(qrcode);
} catch (WriterException e) {
e.printStackTrace();
}
}
}
});
}
}
ZXing库精简版的下载:http://download.csdn.net/detail/a874508605/8546185
布局文件的编写
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/scan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="开始扫描二维码" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="show" />
</LinearLayout>在AndroidManifest.xml文件中声明相应的Activity
<activity android:name="com.zxing.activity.CaptureActivity" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden" > </activity>需要用到的权限
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />相应实现的源码
<span style="font-size:14px;">public class MainActivity extends Activity {
private Button scanButton;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanButton = (Button) findViewById(R.id.scan);
text = (TextView) findViewById(R.id.text);
scanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "你写可以扫描条形码或者二维码", Toast.LENGTH_SHORT).show();
Intent startScan = new Intent(MainActivity.this, CaptureActivity.class);
startActivityForResult(startScan, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resu
4000
ltCode, data);
if (resultCode == RESULT_OK) {
String result = data.getExtras().getString("result");
text.setText(result);
}
}
</span><span style="font-size:14px;">}</span>
Android生成二维码应用
布局文件的编写
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/input" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="请输入要编码的内容" /> <Button android:id="@+id/gen" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="生成二维码" /> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" /> </LinearLayout>
相应实现的源码
public class MainActivity extends Activity {
private EditText input;
private Button genButton;
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input = (EditText) findViewById(R.id.input);
genButton = (Button) findViewById(R.id.gen);
img = (ImageView) findViewById(R.id.img);
genButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String in = input.getText().toString();
if(in.equals("")){
Toast.makeText(MainActivity.this, "请输入文本", Toast.LENGTH_SHORT).show();
}else {
try {
Bitmap qrcode = EncodingHandler.createQRCode(in, 400);
img.setImageBitmap(qrcode);
} catch (WriterException e) {
e.printStackTrace();
}
}
}
});
}
}
相关文章推荐
- android开发(17) 扫描二维码 - 调用第三方APK来实现二维码扫描,参考自 开源项目zxing
- ZXing 为Android应用生成二维码
- android 二维码zxing开发
- android 二维码zxing开发之编译jar文件
- Android平台下利用zxing实现二维码开发
- Android平台下利用zxing实现二维码开发
- android开发 横向扫描二维码zxing
- 基于zxing-lib三步实现Android二维码应用
- Android平台下利用zxing实现二维码开发
- Android开发——通过扫描二维码,打开或者下载Android应用
- Android zxing二维码开发 横屏转竖屏
- Android开发——通过扫描二维码,打开或者下载Android应用
- android开发(17) 扫描二维码 - 调用第三方APK来实现二维码扫描,参考自 开源项目zxing
- SB程序媛学习笔记--Android zxing实现二维码开发
- Android平台下利用zxing实现二维码开发
- Android开发——通过扫描二维码,打开或者下载Android应用
- Android应用开发之扫描二维码和条码的SDK及API
- Android二维码开源项目zxing开发(一)——开发前准备
- 【转】Android平台下利用zxing实现二维码开发
- [置顶] android开发之集成zxing,二维码,以及扫描二维码的功能实现。带源代码下载