Related reading:
Android Development Framework's custom zxing two-dimensional code scanning interface and solving frame stretching problems
This project source address: please click here
Take a look at Zxing's project structure, I'll get it right here.
Look at the activity of the sweep code:
Package com.fanyafeng.barcode.activity;
Import android.content.Intent;
Import Android.graphics.Bitmap;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.support.design.widget.FloatingActionButton;
Import Android.support.design.widget.Snackbar;
Import android.support.v7.app.AppCompatActivity;
Import Android.support.v7.widget.Toolbar;
Import Android.view.View;
Import Android.widget.TextView;
Import Android.widget.Toast;
Import COM.FANYAFENG.BARCODE.R;
Import com.fanyafeng.barcode.BaseActivity;
Import Com.fanyafeng.barcode.util.ImageUtil;
Import com.fanyafeng.barcode.zxing.activity.CaptureActivity;
Import Com.fanyafeng.barcode.zxing.activity.CodeUtils;
You need to match baseactivity, which defaults to Baseactivity, and the default baseactivity is the root of the package name public class Scancodeactivity extends Baseactivity {/**
* Scan Jump Activity Requestcode */public static final int request_code = 111;
/** * Select System picture REQUEST Code */public static final int request_image = 112; /** * Request Camera Permission code */Public STATic Final int request_camera_perm = 101;
Private TextView Tvresult;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_scan_code);
Here the default is to use the top left corner of the toolbar, if you need to use the title as the center of the following annotation code, this comment can be the title = GetString (R.string.title_activity_scan_code);
Initview ();
InitData ();
}//Initialize UI space private void Initview () {Tvresult = (TextView) Findviewbyid (R.id.tvresult);
}//Initialize data private void InitData () {} @Override public void OnClick (View v) {Super.onclick (v);
Switch (V.getid ()) {case R.id.btnscan:intent Intent = new Intent (Getapplication (), captureactivity.class);
Startactivityforresult (Intent, Request_code);
Local scan, identify the two-dimensional code in the album//Intent Intent = new Intent (intent.action_get_content);
Intent.addcategory (intent.category_openable);
Intent.settype ("image/*"); Startactivityforresult (Intent, Request_image);
Break } @Override protected void Onactivityresult (final int requestcode, int resultcode, Intent data) {Super.onacti
Vityresult (Requestcode, ResultCode, data);
/** * Processing Two-dimensional code scanning results */if (Requestcode = = Request_code) {//Processing scan results (displayed on the interface) if (null!= data) {
Bundle Bundle = Data.getextras ();
if (bundle = = null) {return; } if (Bundle.getint (codeutils.result_type) = = codeutils.result_success) {String result = Bundle.getstri
Ng (codeutils.result_string);
Toast.maketext (This, "analytic result:" + results, Toast.length_long). Show ();
Tvresult.settext (result); else if (bundle.getint (codeutils.result_type) = = codeutils.result_failed) {Toast.maketext (scancodeactivity.th
IS, "Parse two-dimensional code failure", Toast.length_long. Show ();
/** * Select System picture and parse/else if (Requestcode = = request_image) {if (data!= null) { Uri uri = Data.getdata ();
try {codeutils.analyzebitmap (Imageutil.getimageabsolutepath (this, URI), new Codeutils.analyzecallback () { @Override public void Onanalyzesuccess (Bitmap mbitmap, String result) {Toast.maketext (Sc
Ancodeactivity.this, "analytic result:" + results, Toast.length_long). Show ();
Tvresult.settext (result); @Override public void onanalyzefailed () {Toast.maketext (scancodeactivity.this, "solution
Analysis of two-dimensional code failure ", Toast.length_long). Show ();
}
});
catch (Exception e) {e.printstacktrace (); }} else if (Requestcode = request_camera_perm) {Toast.maketext (this, "Return from the Settings page ...", Toast.length_short
). Show (); }
}
}
Recognition of local two-dimensional codes in annotations
The above is a small set of Android to introduce the use of zxing scan two-dimensional code example code Analysis, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!