Android Scan two-dimensional code and production of two-dimensional code

Source: Internet
Author: User
Tags switch case dota

Geek College scan QR code and generate two-dimensional code

Package Com.example.testqr;import Android.app.activity;import Android.content.intent;import Android.graphics.bitmap;import Android.os.bundle;import Android.view.menu;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.imageview;import Android.widget.toast;import Com.google.zxing.writerexception;import Com.zxing.activity.captureactivity;import Com.zxing.encoding.encodinghandler;public class Mainactivity extends Activity {private button Startscan;private button    Generateqr;private ImageView Qrimageview;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Startscan = (Button) Findviewbyid (R.id.startscan);        GENERATEQR = (Button) Findviewbyid (R.id.generateqrcode);        Qrimageview = (ImageView) Findviewbyid (R.ID.QRIV); Startscan.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (VieW view) {Intent Intent = new Intent (mainactivity.this,captureactivity.class); Startactivityforresult (Intent, 0);}});  Generateqr.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (view view) {try {Bitmap Bitmap = Encodinghandler.createqrcode ("DotA"); Qrimageview.setimagebitmap (bitmap);}    catch (Writerexception e) {e.printstacktrace ();}}});        @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu);    return true; } @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (ResultCode = =    RESULT_OK) {String str = Data.getstringextra ("result");    Toast.maketext (mainactivity.this, str, 0). Show (); }    }    }

Main description
1: The library is in the Geek College material library is also under the Internet because the error changed the switch case to the IF else
2: Scan QR code is captureactivity
3: A method of generating a two-dimensional code

Bitmap Bitmap = Encodinghandler.createqrcode ("DotA", 400);
Qrimageview.setimagebitmap (bitmap);

  

Android Scan two-dimensional code and production of two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.