安卓史上最简单扫描二维码和生成二维码
来源:互联网 发布:阿里云ddns客户端 编辑:程序博客网 时间:2024/05/01 05:53
private Button button;
private TextView text;
private Button genButton;
private ImageView img;
private EditText input;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
text = (TextView) findViewById(R.id.text);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplication(), "你可以扫描二维码", 0).show();
Intent startScan = new Intent(MainActivity.this,CaptureActivity.class);
startActivityForResult(startScan,0);
}
});
genButton = (Button) findViewById(R.id.gen);
img = (ImageView) findViewById(R.id.img);
input = (EditText) findViewById(R.id.input);
genButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String inputStr = input.getText().toString().trim();
try {
if(!TextUtils.isEmpty(inputStr)){
Bitmap qrcode = EncodingHandler.createQRCode(inputStr, 400);
img.setImageBitmap(qrcode);
}
} catch (WriterException e) {
e.printStackTrace();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0 && resultCode == RESULT_OK){
String result = data.getExtras().getString("result");
text.setText(result);
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android1:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android1:id="@+id/button"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
android1:text="扫描二维码" />
<TextView
android1:id="@+id/text"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
android:layout_below="@id/button"
/>
<EditText
android1:id="@+id/input"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
android:layout_below="@id/text"
android:hint="请输入要编码的内容"
/>
<Button
android1:id="@+id/gen"
android1:layout_width="match_parent"
android1:layout_height="wrap_content"
android1:text="生成二维码"
android:layout_below="@id/input"
/>
<ImageView
android1:id="@+id/img"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content"
android:layout_below="@id/gen"
android:layout_gravity="center"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wxj.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.wxj.activity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="orientation|keyboardHidden"
android:name="com.zxing.activity.CaptureActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
</application>
</manifest>
源码下载地址:http://download.csdn.net/detail/u010648159/8933563
- 安卓史上最简单扫描二维码和生成二维码
- 二维码生成和二维码扫描
- 扫描二维码和生成二维码
- 生成二维码和扫描二维码
- 扫描二维码和生成二维码
- 生成和扫描二维码
- 二维码扫描和生成
- 二维码扫描和生成
- Android 二维码扫描和生成简单实现
- 二维码扫描及简单二维码生成
- 扫描二维码+生成二维码
- 生成二维码和扫描二维码demo分享
- Android生成二维码和扫描二维码zxing
- 二维码的扫描和生成二维码
- 使用ZXing扫描二维码和生成二维码
- 扫描二维码 和 生成二维码
- Android Xzing生成二维码和扫描二维码
- Android 二维码扫描和生成二维码
- Xcode快捷键
- HDU 5311 Hidden String (优美的暴力)
- 写blog的目的
- JavaScript推荐资料合集(前端必看)
- virmon防火墙有了升级
- 安卓史上最简单扫描二维码和生成二维码
- C语言中对文件的操作
- Memcached客户端(memcached-Java-client)与 Spring集成(单服务器)
- 关于路由器上网设置
- Convert Sorted List to Binary Search Tree
- win8 C 盘 突然少了 十几G 空间 原因,解决方法
- c++ 与C# 单例代码简单实现
- 算法分析--数量级比较
- Visual Studio 各版本下载