
使用AndroID Studio
一、在build.gradle(Module:app)添加代码 下载,调用插件
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'}二、添加权限
<?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); } // 扫描按钮点击监听事件 public voID clickScan(VIEw vIEw) { //扫描 *** 作 IntentIntegrator integrator = new IntentIntegrator(MainActivity.this); integrator.initiateScan(); } @OverrIDe protected voID onActivityResult(int requestCode,int resultCode,Intent data) { // 跳转扫描页面返回扫描数据 IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode,resultCode,data); // 判断返回值是否为空 if (scanResult != null) { //返回条形码数据 String result = scanResult.getContents(); Log.d("code",result); Toast.makeText(this,result,Toast.LENGTH_LONG).show(); } }}以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持编程小技巧!
总结以上是内存溢出为你收集整理的详解Android 扫描条形码(Zxing插件)全部内容,希望文章能够帮你解决详解Android 扫描条形码(Zxing插件)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)