There are many kinds of two-dimensional code, but our common use of micro-letter is called a QRCode two-dimensional code, like the following, you can rest assured sweep, this is just my blog homepage link:
About QR code coding of two-dimensional code, we need to know several features:
1. Scanning can be swept from all angles, that is, how many degrees of rotation does not matter, do not believe it? Next time go to KFC to pay a try.
2. Two-D code has a fault-tolerant rate, the greater the fault-tolerant rate, the more complex the resulting two-dimensional code, but the more difficult to error, and when the two-dimensional code is obscured by the easier to scan out. Here I upload the two-dimensional code fault tolerance is 30%, you can start from the upper left corner of the scan, probably scanned to the next picture range can be identified when:
3. Two-D code has a limited character content, and the more content, the more complex the two-dimensional code. If your two-dimensional code is easy to be scanned by some low pixel mobile phone, try not to be too complicated.
Note: Two-dimensional code generation can be done through a variety of web sites, only need to enter the content can be obtained.
Now that the two-dimensional code is generated, we need to know how to scan the cell phone and get what the two-dimensional code represents, here is the simplest Third-party library: Barcodescaner
Through this library, we can directly write an activity for shooting and recognition, and then through the activity returned results to deal with the following specific steps:
1. Adding dependencies
compile ' me.dm7.barcodescanner:zxing:1.8.4 '
2. Create an activity, as shown in the following code:
public class Scanneractivity extends Appcompatactivity implements Zxingscannerview.resulthandler {
private Zxingscannerview Mzxingscannerview;
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Mzxingscannerview = new Zxingscannerview (this); Zxingscannerview as Layout
Setcontentview (Mzxingscannerview);
}
@Override
protected void Onresume () {
super.onresume ();
Mzxingscannerview.setresulthandler (this); Set processing result callback
Mzxingscannerview.startcamera ();//Open Camera
}
@Override
protected void OnPause () {
super.onpause ();
Mzxingscannerview.stopcamera (); Turn off the camera when the activity loses focus
@Override public
void Handleresult {//Implementation callback interface, returning data to and ending the activity
Intent data = new Intent ();
Data.putextra ("Text", Result.gettext ());
Setresult (RESULT_OK, data);
Finish ();
}
3. Open this activity in the main activity and process the returned data:
public class Homeactivity extends Appcompatactivity {private TextView mtextview;
Private WebView Mwebview;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_home);
Mtextview = (TextView) Findviewbyid (r.id.tv);
Mwebview = (webview) Findviewbyid (R.ID.WV);
public void Scancode (the view view) {Startactivityforresult (this, scanneractivity.class), 1); @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult (re
Questcode, ResultCode, data); if (ResultCode = = RESULT_OK) {Mtextview.settext (Data.getstringextra ("text"));//Display the recognized text Mwebview.loadurl (data.gets Tringextra ("text")); Load the identified content as a URL to the WebView}}}
4. Add camera and Access network permissions:
<uses-permission android:name= "Android.permission.CAMERA"/>
<uses-permission android:name= "Android.permission.INTERNET"/>
the method of using this tool class is very simple, only need to use a zxingscannerview as the layout of the entire activity, then set the resolution of the successful callback interface, the method of implementing the callback to return the data to the main activity.
Of course, if you need a custom scan interface effect, it is not so simple.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.