Android掃描和生成二維碼
本文實(shí)例為大家分享了Android掃描和生成二維碼的具體代碼,供大家參考,具體內(nèi)容如下
MainActivity.java
public class MainActivity extends AppCompatActivity { private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button =findViewById(R.id.btn); mImageView =findViewById(R.id.img); button.setOnClickListener(new View.OnClickListener() { //點(diǎn)擊按鈕掃描二維碼 @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this,CaptureActivity.class); startActivityForResult(intent,2); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode==200&& resultCode==RESULT_OK){ if (data!=null){ String content = data.getStringExtra(Constant.CODED_CONTENT); if (TextUtils.isEmpty(content)){ Toast.makeText(MainActivity.this, "您的輸入為空!", Toast.LENGTH_SHORT).show(); return; } Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); try { Bitmap bitmap = CodeCreator.createQRCode(content, 400, 400, logo); mImageView.setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } Toast.makeText(MainActivity.this,"掃描"+content,Toast.LENGTH_SHORT).show(); } } } }
activity.main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="掃一掃"/> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </android.support.constraint.ConstraintLayout>
需要配置的權(quán)限
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.CAMERA"></uses-permission> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.permission.FLASHLIGHT" />
build.gradle
minSdkVersion 16 //配置16 implementation'com.github.yuzhiqiang1993:zxing:2.2.1' //依賴
外部build.gradle
allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } //加這行代碼 } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)掃描和生成二維碼
- Android實(shí)現(xiàn)掃描二維碼功能
- Android studio 實(shí)現(xiàn)手機(jī)掃描二維碼功能
- Android如何實(shí)現(xiàn)掃描和生成二維碼
- Android 二維碼掃描和生成二維碼功能
- android實(shí)現(xiàn)掃描網(wǎng)頁(yè)二維碼進(jìn)行網(wǎng)頁(yè)登錄功能
- Android開發(fā)實(shí)現(xiàn)模仿360二維碼掃描功能實(shí)例詳解
- Android中利用zxing實(shí)現(xiàn)自己的二維碼掃描識(shí)別詳解
- Android詳細(xì)講解谷歌推出的官方二維碼掃描庫(kù)
相關(guān)文章
Android ViewPager中顯示圖片與播放視頻的填坑記錄
這篇文章主要給介紹了關(guān)于Android ViewPager中顯示圖片與播放視頻的一些填坑記錄,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-05-05Android實(shí)現(xiàn)捕獲未知異常并提交給服務(wù)器的方法
這篇文章主要介紹了Android實(shí)現(xiàn)捕獲未知異常并提交給服務(wù)器的方法,涉及Android的異常與錯(cuò)誤處理機(jī)制相關(guān)操作技巧,需要的朋友可以參考下2016-08-08Android貝塞爾曲線實(shí)現(xiàn)消息拖拽消失
這篇文章主要為大家詳細(xì)介紹了Android貝塞爾曲線實(shí)現(xiàn)消息拖拽消失,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01Android?TextView的maxEms和maxLength屬性區(qū)別
這篇文章主要為大家介紹了Android?TextView的maxEms和maxLength屬性區(qū)別,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03Android連接MySQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)方法詳解
這篇文章主要介紹了Android連接MySQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)方法,在Android應(yīng)用程序中連接MySQL數(shù)據(jù)庫(kù)可以幫助開發(fā)人員實(shí)現(xiàn)更豐富的數(shù)據(jù)管理功能,而且在Android中操作數(shù)據(jù)庫(kù)真的太智能了,需要的朋友可以參考下2024-02-02比較完整的android MP3 LRC歌詞滾動(dòng)高亮顯示(附源碼)
比較完整的android MP3 LRC歌詞滾動(dòng)高亮顯示(附源碼)。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-11-11Java程序員轉(zhuǎn)Android開發(fā)必讀經(jīng)驗(yàn)一份
小編最近幾日偷偷的發(fā)現(xiàn)部分Java程序員想轉(zhuǎn)安卓開發(fā),故此加緊補(bǔ)充知識(shí),為大家搜集資料,積極整理前人的經(jīng)驗(yàn),希望可以給正處于困惑中的你,帶來(lái)些許的幫助。2017-11-11Android 關(guān)閉多個(gè)Activity的實(shí)現(xiàn)方法
這篇文章主要介紹了Android 關(guān)閉多個(gè)Activity的實(shí)現(xiàn)方法的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下2017-09-09解析Android點(diǎn)擊事件分發(fā)機(jī)制
本篇文章主要介紹了解析Android點(diǎn)擊事件分發(fā)機(jī)制,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12