欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Android 掃描條形碼(Zxing插件)

 更新時(shí)間:2016年12月19日 14:38:23   投稿:sxyy  
本篇文章主要對(duì)Android 掃描條形碼(Zxing插件)進(jìn)行實(shí)例解析,相信對(duì)大家的學(xué)習(xí)會(huì)有很好的幫助,需要的朋友一起來(lái)看下吧

使用Android Studio

一、在build.gradle(Module:app)添加代碼  下載,調(diào)用插件

apply plugin: 'com.android.application'
android {
 compileSdkVersion 24
 buildToolsVersion "24.0.1"

 defaultConfig {
  applicationId "com.example.ly.scanrfid"
  minSdkVersion 19
  targetSdkVersion 24
  versionCode 1
  versionName "1.0"
 }
 buildTypes {
  release {
   minifyEnabled false
   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  }
 }
 repositories {
  mavenCentral()
  maven {
  url "http://dl.bintray.com/journeyapps/maven"
  }
 }
}
dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:24.2.1'
 // Supports Android 4.0.3 and later (API level 15)
 compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'
 // Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
 // If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
 compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'
 // Convenience library to launch the scanning and encoding Activities.
 // It automatically picks the best scanning library from the above two, depending on the
 // Android version and what is available.
 compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'
 // Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
 // This mostly affects encoding, but you should test if you plan to support these versions.
 // Older versions e.g. 2.2 may also work if you need support for older Android versions.
 compile 'com.google.zxing:core:3.0.1'
}

二、添加權(quán)限

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.ly.scanrfid">
 <uses-permission android:name="android.permission.CAMERA"/>
 <uses-permission android:name="android.permission.VIBRATE"/>
 <uses-permission android:name="android.permission.INTERNET"/>
 <application
  android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">
  <activity android:name=".MainActivity">
   <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
   </intent-filter>
  </activity>
 </application>
</manifest>

三、Activity代碼

package com.example.ly.scanrfid;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class MainActivity extends AppCompatActivity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 // 掃描按鈕點(diǎn)擊監(jiān)聽(tīng)事件
 public void clickScan(View view) {
  //掃描操作
  IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
  integrator.initiateScan();
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // 跳轉(zhuǎn)掃描頁(yè)面返回掃描數(shù)據(jù)
  IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
  //  判斷返回值是否為空
  if (scanResult != null) {
   //返回條形碼數(shù)據(jù)
   String result = scanResult.getContents();
   Log.d("code", result);
   Toast.makeText(this, result, Toast.LENGTH_LONG).show();
  }
 }
}

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • Android源碼中的目錄結(jié)構(gòu)詳解

    Android源碼中的目錄結(jié)構(gòu)詳解

    這篇文章主要介紹了Android源碼中的一些目錄結(jié)構(gòu),方法需要的朋友
    2013-06-06
  • Android接收和發(fā)送短信處理

    Android接收和發(fā)送短信處理

    這篇文章主要介紹了Android接收和發(fā)送短信處理的相關(guān)資料,具有一定的參考價(jià)值,需要的朋友可以參考下
    2016-01-01
  • Android Studio不能獲取遠(yuǎn)程依賴包的完美解決方法

    Android Studio不能獲取遠(yuǎn)程依賴包的完美解決方法

    這篇文章主要介紹了Android Studio不能獲取遠(yuǎn)程依賴包的解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-11-11
  • Android編程解析XML方法詳解(SAX,DOM與PULL)

    Android編程解析XML方法詳解(SAX,DOM與PULL)

    這篇文章主要介紹了Android編程解析XML方法,結(jié)合實(shí)例形式詳細(xì)分析了Android解析XML文件的常用方法與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • ImageSwitcher圖像切換器的使用實(shí)例

    ImageSwitcher圖像切換器的使用實(shí)例

    這篇文章主要為大家詳細(xì)介紹了ImageSwitcher圖像切換器的使用實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Android 邊播邊緩存的實(shí)現(xiàn)(MP4 未加密m3u8)

    Android 邊播邊緩存的實(shí)現(xiàn)(MP4 未加密m3u8)

    這篇文章主要介紹了Android 邊播邊緩存的實(shí)現(xiàn)(MP4 未加密m3u8),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android視圖綁定viewBinding的使用介紹

    Android視圖綁定viewBinding的使用介紹

    最近這段時(shí)間在學(xué)習(xí)Kotlin,突然發(fā)現(xiàn)谷歌已經(jīng)把kotlin-android-extensions插件廢棄,目前推薦使用ViewBinding來(lái)進(jìn)行替代,接下來(lái)通過(guò)本文給大家分享Android使用ViewBinding的詳細(xì)步驟,感興趣的朋友一起學(xué)習(xí)吧
    2023-01-01
  • Android小知識(shí)之圖片的3種壓縮方式小結(jié)

    Android小知識(shí)之圖片的3種壓縮方式小結(jié)

    這篇文章主要給大家介紹了關(guān)于Android小知識(shí)之圖片的3種壓縮方式的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • Android Gradle開(kāi)發(fā)指南詳解

    Android Gradle開(kāi)發(fā)指南詳解

    這篇文章主要為大家詳細(xì)介紹了Android Gradle開(kāi)發(fā)指南的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Android ListView彈性效果的實(shí)現(xiàn)方法

    Android ListView彈性效果的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Android ListView彈性效果的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下
    2016-05-05

最新評(píng)論