Zxing扫描二维码和本地的二维码和内存溢出000M

1:Zxing
第一步 :依赖 implementation ‘cn.yipianfengye.android:zxing-library:2.2’
第二步:在application里面初始化 ZXingLibrary.initDisplayOpinion(this);
用到的权限:
(uses-feature android:name=“android.hardware.camera” />
uses-feature android:name=“android.hardware.camera.autofocus” />
uses-permission android:name=“android.permission.VIBRATE” />
uses-permission android:name=“android.permission.WAKE_LOCK” />
uses-permission android:name=“android.permission.READ_EXTERNAL_STORAGE” />
uses-permission android:name=“android.permission.WRITE_EXTERNAL_STORAGE” />
uses-permission android:name=“android.permission.INTERNET” />)
第三步:代码一 扫描二维码
给一个按钮点击事件跳转:
Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
startActivityForResult(intent,100);
然后调用activityforresult
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode100){
Bundle extras = data.getExtras();
if (extras
null){
return;
}
else if (extras.getInt(CodeUtils.RESULT_TYPE)==CodeUtils.RESULT_SUCCESS){
String string = extras.getString(CodeUtils.RESULT_STRING);
Toast.makeText(this, “这是我的”+string, Toast.LENGTH_SHORT).show();
}
else if (extras.getInt(CodeUtils.RESULT_TYPE)==CodeUtils.RESULT_FAILED){
Toast.makeText(this, “失败”, Toast.LENGTH_SHORT).show();
}
}
}

代码二 内存中的二维码
同样也是一个点击事件
String btimp=Environment.getExternalStorageDirectory()+"/Pictures/wzy.png";//二维码路劲
Log.i(“wzy”, "onClick: "+btimp);
CodeUtils.analyzeBitmap(btimp, new CodeUtils.AnalyzeCallback() {
@Override
public void onAnalyzeSuccess(Bitmap mBitmap, String result) {
Toast.makeText(MainActivity.this, “解析结果”+result, Toast.LENGTH_SHORT).show();
}

                @Override
                public void onAnalyzeFailed() {
                    Toast.makeText(MainActivity.this, "解析二维码", Toast.LENGTH_SHORT).show();
                }
            });

2:内存溢出00M so easy
依赖:
debugImplementation ‘com.squareup.leakcanary:leakcanary-android:1.5’
releaseImplementation ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5’
testImplementation ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5’

application中初始化:
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
Log.i(“Www”, "onCreate: ");
return;
}
LeakCanary.install(this);

你可能感兴趣的:(Zxing扫描二维码和本地的二维码和内存溢出000M)