本文主要是介绍zxing实现二维码解析和生成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、扫描二维码须在AndroidManifest.xml添加用户权限,主要是摄像头,手机振动权限
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>
2、为跳转到扫描二维码的页面(Activity),必须将该Activity写入AndroidManifest.xml
<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>
3、开启扫描Activity
Intent intent = new Intent(MainActivity.this, CaptureActivity.class);startActivityForResult(intent, 0);
重写onActivityResult方法
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);if (resultCode == RESULT_OK) {showinfo.setText(data.getExtras().getCharSequence("result"));}}
4、输入文本信息生成二维码(Bitmap),将二维码用ImageView显示
try {Bitmap barcodeBitmap = EncodingHandler.createQRCode(inputinfo.getText().toString(), 400);barcode.setImageBitmap(barcodeBitmap);} catch (WriterException e) {// TODO Auto-generated catch blocke.printStackTrace();}
这篇关于zxing实现二维码解析和生成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!