Android sdutio配置Zxing進行掃碼功能的實現(xiàn)方法
最快的調(diào)用Zxing方法
1.關(guān)聯(lián)第三方庫
2.調(diào)用基礎(chǔ)的掃碼
3.獲取返回值
具體代碼如下:
//1.默認(rèn)選項啟動意圖
new IntentIntegrator(MainActivity.this).initiateScan(); // `this` is the current Activity
//2.獲取得到的結(jié)果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "取消掃碼", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "掃碼結(jié)果:" + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
MainActivity.java
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "wei.shm.zxingscancode"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
//新建項目只增加這個
compile 'com.journeyapps:zxing-android-embedded:3.5.0'
//需要核對的有:
//1.備置倉庫:repositories里的jcenter()
//2.com.android.support:appcompat-v7:版本號必須大于23以上
//3.buildToolsVersion:版本需要大于等于23.0.2,舊版本可能會導(dǎo)致編譯錯誤
//以上條件都滿足則只需要添加 compile 'com.journeyapps:zxing-android-embedded:3.5.0'
}
IntentIntegrator相關(guān)方法注解翻譯
setCaptureActivity:設(shè)置活動類使用。它可以是任何活動,但應(yīng)處理的意圖額外使用這里。
setPrompt:設(shè)置一個提示顯示在捕捉屏幕上,而不是使用默認(rèn)。
setOrientationLocked:默認(rèn)情況下,方向鎖定。設(shè)置為false不鎖定。
setCameraId:使用指定的相機ID。
setBeepEnabled:設(shè)置為false禁用掃描的嗶嗶聲。
setBarcodeImageEnabled:設(shè)置為true,以便在結(jié)果意圖中保存條形碼圖像并發(fā)送其路徑。
setDesiredBarcodeFormats:設(shè)置所需的條碼格式掃描。
initiateScan:啟動掃描所有已知的條形碼類型與默認(rèn)相機。
setTimeout:啟動掃描所有已知的條形碼類型與默認(rèn)相機。并啟動計時器超時完成
createScanIntent:使用指定選項創(chuàng)建掃描意圖。
以上所述是小編給大家介紹的Android sdutio配置Zxing進行掃碼功能的實現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android實現(xiàn)excel/pdf/word/odt/圖片相互轉(zhuǎn)換
這篇文章主要為大家詳細介紹了Android如何實現(xiàn)excel/pdf/word/odt/圖片之間的相互轉(zhuǎn)換,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2023-04-04

