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開發(fā)實(shí)現(xiàn)拍照功能的方法實(shí)例解析
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)拍照功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android拍照功能的具體實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
Android實(shí)現(xiàn)TextView中的部分文字實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)功能
在移動(dòng)端應(yīng)用中,往往需要在一段文字中讓某幾個(gè)關(guān)鍵詞或短語(yǔ)具備點(diǎn)擊跳轉(zhuǎn)功能,如果將整段文字放到 Button、Link 或單獨(dú)的 View 中,通常會(huì)帶來布局復(fù)雜、樣式難以統(tǒng)一、可維護(hù)性差等問題,所以本文將給大家介紹Android實(shí)現(xiàn)TextView中的部分文字實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)功能2025-04-04
詳解Android自定義控件屬性TypedArray以及attrs
這篇文章主要為大家介紹了android自定義控件屬性TypedArray以及attrs,感興趣的小伙伴們可以參考一下2016-01-01
Android?TextView跑馬燈實(shí)現(xiàn)原理及方法實(shí)例
字的跑馬燈效果在移動(dòng)端開發(fā)中是一個(gè)比較常見的需求場(chǎng)景,下面這篇文章主要給大家介紹了關(guān)于Android?TextView跑馬燈實(shí)現(xiàn)原理及方法的相關(guān)資料,需要的朋友可以參考下2022-05-05
Android中懸浮窗口的實(shí)現(xiàn)原理實(shí)例分析
這篇文章主要介紹了Android中懸浮窗口的實(shí)現(xiàn)原理,以實(shí)例形式較為詳細(xì)的分析了Android懸浮窗口的原理與具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android設(shè)備adb連接后顯示device unauthorized解決方案
這篇文章主要為大家介紹了Android設(shè)備adb連接后顯示device unauthorized解決方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
Android實(shí)現(xiàn)分享微信好友及出現(xiàn)閃退的解決辦法
這篇文章主要介紹了Android實(shí)現(xiàn)分享微信好友及出現(xiàn)閃退的解決辦法的相關(guān)資料,需要的朋友可以參考下2016-03-03
Android中截取當(dāng)前屏幕圖片的實(shí)例代碼
該篇文章是說明在Android手機(jī)或平板電腦中如何實(shí)現(xiàn)截取當(dāng)前屏幕的功能,并把截取的屏幕保存到SDCard中的某個(gè)目錄文件夾下面。實(shí)現(xiàn)的代碼如下:2013-08-08
發(fā)布?Android?library?到?Maven?解析
這篇文章主要介紹了發(fā)布?Android?library到Maven解析,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09

