{"id":1086,"date":"2015-11-30T15:14:11","date_gmt":"2015-11-30T23:14:11","guid":{"rendered":"http:\/\/appinventor.pevest.com\/?p=1086"},"modified":"2015-11-30T15:14:11","modified_gmt":"2015-11-30T23:14:11","slug":"scanning-bar-codes-and-qr-codes-with-app-inventor-apps","status":"publish","type":"post","link":"https:\/\/coldstreams.com\/appinventor\/2015\/11\/30\/scanning-bar-codes-and-qr-codes-with-app-inventor-apps\/","title":{"rendered":"Scanning bar codes and QR Codes with App Inventor Apps"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>App Inventor supports scanning of product identification &#8220;bar codes&#8221; and QR codes. Bar codes are typically found on consumer product packaging. QR codes are used for web addresses (so you can scan the QR code and go directly to the web address), part and product inventory tracking, and to deliver short messages.<\/p>\n<p>In this tutorial, we create a simple App Inventor app to scan bar and QR codes.<\/p>\n<p><strong>Update<\/strong>:<em>\u00a0Jos\u00e9 Luis N\u00fa\u00f1ez provides his own tutorial (in Spanish) for a bar code scanning app to check seating in a theater (written in App Inventor). Watch it on Youtube here:\u00a0\u00a0<a class=\"yt-uix-sessionlink g-hovercard spf-link \" href=\"https:\/\/www.youtube.com\/channel\/UCTrQFPQYfQNUBxoAPPFUqiw\" data-ytid=\"UCTrQFPQYfQNUBxoAPPFUqiw\" data-sessionlink=\"itct=CDoQ4TkiEwiQ_bKOobzJAhVUon4KHR1-AE4o-B0\">Curso de App Inventor 2 (Jos\u00e9 Luis N\u00fa\u00f1ez)<\/a><\/em><\/p>\n<h2>User Interface<\/h2>\n<p>Our App Inventor app has a simple user interface &#8211; a single button to scan either a bar or QR code. When pressed, the app activates the camera to scan the code and then returns a <em>result<\/em> value.<\/p>\n<p>If the code is a numeric bar code value, the app displays a web page of information about the item corresponding to the bar code. If the returned code contains a web address, then that web address is displayed on screen. Here is an example from scanning the UPC code on a package of tea:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/Screenshot_20151130-134823.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1091\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/Screenshot_20151130-134823-576x1024.png\" alt=\"Screenshot_20151130-134823\" width=\"350\" height=\"622\" \/><\/a>In the next example, a QR code containing http:\/\/appinventor.mit.edu is scanned:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/static_qr_code_without_logo.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1093 aligncenter\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/static_qr_code_without_logo.png\" alt=\"static_qr_code_without_logo\" width=\"182\" height=\"182\" \/><\/a>And here is the result:<\/p>\n<h2><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/Screenshot_20151130-134746.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1092\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/Screenshot_20151130-134746.png\" alt=\"Screenshot_20151130-134746\" width=\"350\" height=\"622\" \/><\/a>Designer View<\/h2>\n<p>Drag a <em>WebViewer<\/em> component from the Palette&#8217;s User Interface section, and drag a <em>BarCodeScanner<\/em> component from the Sensor&#8217;s section. The <em>WebViewer<\/em> is the &#8220;earth&#8221; icon in this screen, and the <em>BarCodeScanner<\/em> is an invisible component, below the canvas area.<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeDesigner.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1087\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeDesigner.gif\" alt=\"BarCodeDesigner\" width=\"350\" height=\"590\" \/><\/a>Two labels are used &#8211; one to display the text &#8220;Result:&#8221; and the other to display the returned code.<\/p>\n<h2><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeComponents.gif\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1088 aligncenter\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeComponents.gif\" alt=\"BarCodeComponents\" width=\"189\" height=\"194\" \/><\/a>Blocks Code<\/h2>\n<p>To activate the <em>BarCodeScanner<\/em>, we call the <em>DoScan<\/em> method:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeBlocks1.gif\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1089 aligncenter\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeBlocks1.gif\" alt=\"BarCodeBlocks1\" width=\"376\" height=\"96\" \/><\/a>The above activates the camera and displays a view on screen (in Landscape mode). Once a bar code or QR code is successfully scanned, the camera is automatically turned off and an <em>AfterScan<\/em> event is generated.<\/p>\n<p>The <span style=\"text-decoration: underline;\"><em>AfterScan<\/em><\/span> event has one parameter named <em>result<\/em>; this contains the converted scan code &#8211; a numeric value for a bar code or an <em>http:\/\/<\/em> URL for a web address (anything else is displayed in the <em>lblBarCodeResult<\/em> label, on screen).<\/p>\n<h2><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeBlocks2.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1090 aligncenter\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/11\/BarCodeBlocks2.gif\" alt=\"BarCodeBlocks2\" width=\"479\" height=\"266\" \/><\/a>Creating QR Codes<\/h2>\n<p>To create your own QR Code images use any of the QR code generators available online &#8211; just search for &#8220;Create QR Code free&#8221; &#8211; I used <a href=\"http:\/\/www.qrstuff.com\/\">http:\/\/www.qrstuff.com\/<\/a><\/p>\n<h2>Download Source<\/h2>\n<p>Right Click (or Ctrl-Click on Mac OS X) and choose &#8220;Save as&#8221; (or similar wording): <a href=\"http:\/\/appinventor.pevest.com\/source\/tutorials\/BarCode_Scanner.aia\">BarCode_Scanner.aia<\/a><\/p>\n<h2>E-Books and Printed Books<\/h2>\n<p>If you find these tutorials helpful (I hope you do!) please take a look at my books on App Inventor. To learn more about the books and where to get them (they are inexpensive) please see my <a href=\"http:\/\/appinventor.pevest.com\/?page_id=33\">App Inventor Books page<\/a>.<\/p>\n<ul>\n<li><strong>App Inventor 2 Introduction (Volume 1 e-book)<\/strong><br \/>\nStep-by-step guide to easy Android programming<\/li>\n<li><strong>App Inventor 2 Advanced Concepts\u00a0(Volume\u00a02 e-book)<\/strong><br \/>\nStep-by-step guide\u00a0to\u00a0Advanced features including TinyDB<\/li>\n<li><strong>App Inventor 2 Databases and Files<\/strong>\u00a0<strong>(Volume 3 e-book)<\/strong><br \/>\nStep-by-step TinyDB, TinyWebDB, Fusion Tables and Files<\/li>\n<li><strong>App Inventor 2 Graphics, Animation and Charts (Volume 4 e-book <em>and printed book<\/em>)<\/strong><br \/>\nStep-by-step guide to graphics, animation and charts<\/li>\n<\/ul>\n<p>Thank you for visiting! &#8212; Ed<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview App Inventor supports scanning of product identification &#8220;bar codes&#8221; and QR codes. Bar codes are typically found on consumer product packaging. QR codes are used for web addresses (so you can scan the QR code and go directly to the web address), part and product inventory tracking, and to deliver short messages. In this &hellip; <a href=\"https:\/\/coldstreams.com\/appinventor\/2015\/11\/30\/scanning-bar-codes-and-qr-codes-with-app-inventor-apps\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Scanning bar codes and QR Codes with App Inventor Apps<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10,12],"tags":[19,21,22,28,31,37,38,156,160,161,178,181],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-components","category-programming-method","category-stem-education","tag-android","tag-app","tag-app-inventor","tag-appinventor","tag-apps","tag-bar-code","tag-barcode","tag-qr-code","tag-scanner","tag-scanning","tag-source","tag-stem"],"_links":{"self":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":0,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"wp:attachment":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}