minSdkVersion >= 14
本项目依赖于ZXing 3.2.1
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<activity android:name="io.github.xudaojie.qrcodelib.CaptureActivity"/>
Intent i = new Intent(mContent, CaptureActivity.class);
startActivityForResult(i, REQUEST_QR_CODE);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK
&& requestCode == REQUEST_QR_CODE
&& data != null) {
String result = data.getStringExtra("result");
Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
}
}
想引入你的项目,需要修改你的build.gradle
repositories {
maven { url "http://repo1.maven.org/maven2" }
maven { url 'https://jitpack.io' }
}
compile('com.github.XuDaojie:QRCode-Android:v0.1.0', {
exclude group: 'com.android.support'
})
// 6.0权限控制需要support支持
compile 'com.android.support:appcompat-v7:$supportVersion'