Development often encountered QR code scan operation, the previous period of time to do the project to achieve this function, so the online search for information to achieve, and now to do it for you to share, mainly includes two-dimensional code scanning and generation of two-dimensional code card.
Let's take a look:
Generated QR code, open sweep sweep can see the generated business card, can be saved in the contact.
Two-dimensional code scanning methods such as:
Generate Business Card Code
Public classBusinesscardactivityextendsactivity{PrivateEditText Et_only_company; PrivateEditText et_only_position; PrivateEditText Et_only_phone; PrivateEditText Et_only_email; PrivateEditText Et_only_web1; PrivateEditText Et_only_add; PrivateEditText Et_only_note; PrivateEditText Et_only_name; @Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_generate); Et_only_company=(EditText) Findviewbyid (R.id.et_only_company); Et_only_position=(EditText) Findviewbyid (r.id.et_only_position); Et_only_phone=(EditText) Findviewbyid (R.id.et_only_phone); Et_only_email=(EditText) Findviewbyid (R.id.et_only_email); Et_only_web1=(EditText) Findviewbyid (R.ID.ET_ONLY_WEB1); Et_only_add=(EditText) Findviewbyid (R.id.et_only_add); Et_only_note=(EditText) Findviewbyid (r.id.et_only_note); Et_only_name=(EditText) Findviewbyid (r.id.et_only_name); Initview (); } Private voidInitview () {Findviewbyid (r.id.but). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubString name =Et_only_name.gettext (). toString (). Trim (); String Company=Et_only_company.gettext (). toString (). Trim (); String position=Et_only_position.gettext (). toString (). Trim (); String Phone=Et_only_phone.gettext (). toString (). Trim (); String Email=Et_only_email.gettext (). toString (). Trim (); String Web1=Et_only_web1.gettext (). toString (). Trim (); String Add=Et_only_add.gettext (). toString (). Trim (); String Note=Et_only_note.gettext (). toString (). Trim (); String Contents= "begin:vcard\nversion:3.0\n" + "N:" +name+ "\norg:" + company + "\ntitle:" +position+ "\nnote:" + Note + "\ntel:" + Phone + "\nadr:" +Add+ "\nurl:" + Web1 + "\nemail:" + email + "\nend:vcard"; Try{Bitmap BM=Qr_code (contents, barcodeformat.qr_code); ImageView img=(ImageView) Findviewbyid (r.id.img_only); Img.setimagebitmap (BM); } Catch(writerexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }); } PublicBitmap Qr_code (string string, Barcodeformat format)throwswriterexception {multiformatwriter writer=NewMultiformatwriter (); Hashtable<encodehinttype, string> HST =NewHashtable<encodehinttype, string>(); Hst.put (Encodehinttype.character_set,"UTF-8"); Bitmatrix Matrix= Writer.encode (string, format, 400, 400, HST); intwidth =matrix.getwidth (); intHeight =matrix.getheight (); int[] pixels =New int[Width *height]; for(inty = 0; Y < height; y++) { for(intx = 0; x < width; X + +) { if(Matrix.get (x, y)) {pixels[y* width + x] = 0xff000000; }}} Bitmap Bitmap=bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888); //generate bitmap by pixel Group, reference APIBitmap.setpixels (pixels, 0, width, 0, 0, width, height); returnbitmap; }}
A bit more source code is not affixed out, directly download the source code can be.
source Click to download
Android scan QR code and generate business card QR code based on input information