Using Android Studio
First, in Build.gradle (module:app) Add code download, invoke plug-in
Apply plugin: ' Com.android.application ' android {compilesdkversion buildtoolsversion "24.0.1" Defaultconfig {a Pplicationid "Com.example.ly.scanrfid" minsdkversion targetsdkversion versioncode 1 Versionname "1.0"} BU Ildtypes {release {minifyenabled false proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' proguard-r Ules.pro '}} repositories {mavencentral () Maven {URL ' Http://dl.bintray.com/journeyapps/maven '}}} Depen dencies {Compile filetree (dir: ' Libs ', include: [' *.jar ']] testcompile ' junit:junit:4.12 ' compile ' : appcompat-v7:24.2.1 '//Supports Android 4.0.3 and later (API level) compile ' com.journeyapps:zxing-android-embedded
: 2.0.1@aar '//Supports Android 2.1 and later (API level 7), but not optimal to later for Android versions.
If you have the supporting Android 4.0.3 and up, don ' t need to include this. Compile ' com.journeyapps:zxing-android-legacy:2.0.1@aar '//convenience The 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 a
vailable. Compile ' com.journeyapps:zxing-android-integration:2.0.1@aar '//Version 3.0.x of zxing core contains some code is n
OT compatible on Android 2.2 and earlier.
This mostly affects encoding and but you should test if you are to support these versions.
Older versions e.g. 2.2 may also work if to need support for the for older Android versions.
Compile ' com.google.zxing:core:3.0.1 '}
Second, add permissions
<?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>
Third, Activity code
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) {s
Uper.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main); //Scan button click on Listener event public void Clickscan (view view) {//scan operation Intentintegrator Integrator = new Intentintegrator (mainact
Ivity.this);
Integrator.initiatescan (); @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {//Jump Scan page returns scan data intentre
Sult Scanresult = Intentintegrator.parseactivityresult (Requestcode, ResultCode, data); To determine if the return value is an empty if (Scanresult!= null) {//Return barcode data String result = Scanresult. getcontents ();
LOG.D ("code", result);
Toast.maketext (this, result, Toast.length_long). Show ();
}
}
}
Above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!