Android sdutio配置Zxing進(jìn)行掃碼功能的實(shí)現(xiàn)方法
最快的調(diào)用Zxing方法
1.關(guān)聯(lián)第三方庫(kù)
2.調(diào)用基礎(chǔ)的掃碼
3.獲取返回值
具體代碼如下:
//1.默認(rèn)選項(xiàng)啟動(dòng)意圖 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' //新建項(xiàng)目只增加這個(gè) compile 'com.journeyapps:zxing-android-embedded:3.5.0' //需要核對(duì)的有: //1.備置倉(cāng)庫(kù):repositories里的jcenter() //2.com.android.support:appcompat-v7:版本號(hào)必須大于23以上 //3.buildToolsVersion:版本需要大于等于23.0.2,舊版本可能會(huì)導(dǎo)致編譯錯(cuò)誤 //以上條件都滿足則只需要添加 compile 'com.journeyapps:zxing-android-embedded:3.5.0' }
IntentIntegrator相關(guān)方法注解翻譯
setCaptureActivity:設(shè)置活動(dòng)類使用。它可以是任何活動(dòng),但應(yīng)處理的意圖額外使用這里。
setPrompt:設(shè)置一個(gè)提示顯示在捕捉屏幕上,而不是使用默認(rèn)。
setOrientationLocked:默認(rèn)情況下,方向鎖定。設(shè)置為false不鎖定。
setCameraId:使用指定的相機(jī)ID。
setBeepEnabled:設(shè)置為false禁用掃描的嗶嗶聲。
setBarcodeImageEnabled:設(shè)置為true,以便在結(jié)果意圖中保存條形碼圖像并發(fā)送其路徑。
setDesiredBarcodeFormats:設(shè)置所需的條碼格式掃描。
initiateScan:啟動(dòng)掃描所有已知的條形碼類型與默認(rèn)相機(jī)。
setTimeout:啟動(dòng)掃描所有已知的條形碼類型與默認(rèn)相機(jī)。并啟動(dòng)計(jì)時(shí)器超時(shí)完成
createScanIntent:使用指定選項(xiàng)創(chuàng)建掃描意圖。
以上所述是小編給大家介紹的Android sdutio配置Zxing進(jìn)行掃碼功能的實(shí)現(xiàn)方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android實(shí)現(xiàn)excel/pdf/word/odt/圖片相互轉(zhuǎn)換
這篇文章主要為大家詳細(xì)介紹了Android如何實(shí)現(xiàn)excel/pdf/word/odt/圖片之間的相互轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-04-04Android Activity進(jìn)出動(dòng)畫三種方法
這篇文章主要介紹了Android Activity進(jìn)出動(dòng)畫三種方法的相關(guān)資料,需要的朋友可以參考下2017-05-05Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法
今天小編就為大家分享一篇Android 使用地圖時(shí)的權(quán)限請(qǐng)求方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07怎樣才能導(dǎo)入別人的android項(xiàng)目不再報(bào)錯(cuò)
每次看到好的項(xiàng)目都想拿過來看看源碼,可是導(dǎo)入以后各種報(bào)錯(cuò)怎么辦?源碼有問題嗎?有這種可能,但更多的可能性是你沒有正確導(dǎo)入這個(gè)項(xiàng)目2021-08-08