App Inventor Tutorial 11 QR Code Reader



Similar documents
Or working offline with the local server: Once you have the App Inventor running type into your browser

Mobile Apps with App Inventor

This chapter introduces the following App Inventor components and concepts:

App Inventor Tutorial 4 Cat & Mouse Game

GOOGLE DOCS APPLICATION WORK WITH GOOGLE DOCUMENTS

CHAPTER 1 HelloPurr. The chapter covers the following topics:

TalkToMe: A beginner App Inventor app

Google Docs A Tutorial

Agile ICT Website Starter Guides

Adding A Student Course Survey Link For Fully Online Courses Into A Canvas Course

App Inventor Drum Machine Instructions (Project #1) (Version 2 of App Inventor) Description:

Creating a Website with Google Sites

App Inventor Beginner Tutorials

Getting started 7. Designing interfaces 27

(These instructions are only meant to get you started. They do not include advanced features.)

User Guide. What is AeroFS. Installing AeroFS. Learn How to Install AeroFS and get started syncing and sharing securely INTRODUCTION

I Have a Dream, a Two-Part Introductory Tutorial

Building A Web Database Using Contextual Mode

College of Continuing Education Video Production Room

Creating a Website with Google Sites

Terminal Four. Content Management System. Moderator Access

How To Use Standard Pos On A Pc Or Macbook Powerbook (Powerbook 2)

American Sign Language Alphabet App (Project #2) (Version 2 of App Inventor) Description:

Android, Where s My Car?

How To Insert Hyperlinks In Powerpoint Powerpoint

Store & Share Quick Start

Barcode Support. Table of Contents

Google Sites: Site Creation and Home Page Design

BSU Workshop Advanced Forms

Appendix A How to create a data-sharing lab

Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7. Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7

NJCU WEBSITE TRAINING MANUAL

Chapter 14: Links. Types of Links. 1 Chapter 14: Links

Adobe Dreamweaver - Basic Web Page Tutorial

Chapter 4: Website Basics

ClickView Digital Signage User Manual

Google Sites. How to create a site using Google Sites

Basic Pivot Tables. To begin your pivot table, choose Data, Pivot Table and Pivot Chart Report. 1 of 18

Table of Contents. 1.1 Description of DFM... 5

Microsoft Office 365 Outlook Web App (OWA)

DUO SECURITY CISCO VPN USER GUIDE 1/27/2016

Teacher Training Session 1. Adding a Sub-Site (New Page) Editing a page and page security. Adding content cells. Uploading files and creating folders

Download Google Drive to windows 7

Sage Accountants Business Cloud EasyEditor Quick Start Guide

Scientific m-learning. 4-7 June Mobile Application Development using App Inventor for Android Devices

Remote Viewer Recording Backup

Create your own teacher or class website using Google Sites

Ladybug Chase. What You ll Build. What You ll Learn

Creating Serial Numbers using Design and Print Online. Creating a Barcode in Design and Print Online. Creating a QR Code in Design and Print Online

Outlook Web App. in Office 365. The Outlook Window. Signing In. (Outlook Exchange Faculty & Staff) Getting Started

CAS CLOUD WEB USER GUIDE. UAB College of Arts and Science Cloud Storage Service

PDF MAPS FOR SMARTPHONES AND TABLETS

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

How To Write A Cq5 Authoring Manual On An Ubuntu Cq (Windows) (Windows 5) (Mac) (Apple) (Amd) (Powerbook) (Html) (Web) (Font

For Use with QR Code Scanner / Reader Enabled Applications

Tutorial How to upgrade firmware on Phison S5 controller MyDigitalSSD

Hello Purr. What You ll Learn

Windows XP Home Edition / Windows XP Professional

Pendragon Forms Industrial

How to Use Google Cloud Print

Xylophone. What You ll Build

Microsoft Office 365 Outlook Web App (OWA)

Step 1. Step 2. Open your browser and go to and you will be presented a logon screen show below.

Installing Google Drive for Windows 7

Welcome to the Notability User Guide Find what you re looking for quickly using the search icon.

Knowledge Base for Electronic Editing Tools

Introduction. Office of Web and New Media Missouri State University 901 S. National Ave. Springfield, MO 65897

Quick Start Guide Mobile Entrée 4

FlashAir Configuration Software. User s Manual. (Windows) Revision 2

MailChimp Instruction Manual

Vodafone Business Product Management Group. Hosted Services EasySiteWizard Pro 8 User Guide

Presidents Quiz. What You ll Learn

Connecting Software Connect Bridge - Mobile CRM Android User Manual

Drive. Etobicoke-Mimico Watershed Coalition

Strategic Asset Tracking System User Guide

EFORMS MANUAL FOR SHAREPOINT ONLINE

Fingerprint Identity User Manual for the Griaule Biometric Framework Rev 1.00

Document OwnCloud Collaboration Server (DOCS) User Manual. How to Access Document Storage

OneNote 2013 Tutorial

Using SANDBOXIE to Safely Browse the Internet (verified with ver 4.20) Jim McKnight Sandboxie.lwp revised

Mobility with Eye-Fi Scanning Guide

Sync Tool for Clarion NX700/NX509/NP509 Series

ADDENDUM HDS Gen3 sw release 1.5

E-Map Application CHAPTER. The E-Map Editor

Using Flow Control with the HEAD Recorder

user guide phone 2015 by Sysco. All rights reserved.

Grid-In-Hand Mobile Grid Revised 1/27/15

Iowa IDEA Supported Browsers and Settings July 1, 2013 Release

Faculty Web Editing. Wharton County Junior College Employee Training Manual

BallBounce: A simple game app

Introduction to Microsoft Access 2003

Online File Folder. Getting Started Guide. Become an Expert at Managing Your Files Online. wind. Online File Folder // Getting Started Guide

FORM SIMPLICITY QUICK REFERENCE GUIDE PROFESSIONAL/ULTIMATE EDITION

Site Configuration Mobile Entrée 4

Akin Gump Strauss Hauer & Feld LLP Remote Access Resources (DUO)

Intellect Platform - Tables and Templates Basic Document Management System - A101

QR Code Functionality for Wildland Fire Mapping Jarl Moreland USFS GIS Specialist Albuquerque, NM R3RO

Transcription:

App Inventor Tutorial 11 QR Code Reader This is an app which will demonstrate the use of the phone s built in camera as an input device for a QR Code scanner. Note this app will not work on the emulator because it is using the camera module as an input. Please note: before this app will work it requires XZing Barcode Scanner to be installed on the device also. This app is the quickest way to install dependencies which App Inventor Barcode scanners need to function. A compatible version of XZing Barcode Scanner can be found by searching the Google Play Store. If the Google Play Store version is not compatible with your device you can install a depreciated version compatible with most phones, the app is available here. This can be copied to the phones SD card and installed by opening the file in the phones file manager app (if available) or through HTC Sync software. What you will develop is a simple app which allows you to create a QR Code (with your own text) and read a QR code with the phone s built in camera.

Step 1: Open App Inventor Navigate to app inventor as before via http://beta.appinventor.mit.edu and login. Like the previous tutorials, create a new project. Give the project the name QRCodeReader and click OK. Step 2: Build the Interface of QR Code Reader The QR Code Reader app needs many components. These include: Text box Buttons Labels Activity Starter Barcode Scanner Sound Let s start by changing the title from Screen1 to QR Code Reader in the properties box. Now that the title has been changed we need to start adding content to the screen.

The first item we are adding is the button to initiate the Barcode scanning. Change the default text in the button to Scan and adjust the Width attribute of the button to Fill parent in the properties section. The properties section should look as such: Select the Button (from the components section beside properties) and click Rename below. Change the New Name: text value to scanbutton and click ok.

Next we will add a Label to the screen, to display the scan result. Drag a label component from the Basic Palette and place it beneath the Scan button. Delete the Text value of the label as this should be blank prior to the scanning of our Code. Rename the label as shown before and change it to resultlabel.

Drag another button from the Palette section and place it below this label. Following the same steps as before, edit the text for this button and change it to Result Action in the properties section: Then rename this button again as before and call it resultactionbutton. The final two components to be added to the screen are the BarcodeScanner and ActivityStarter, both of which are found on the Other stuff Palette.

Drag one of each to the screen and they will appear below the viewer as non-visible components. Your Components section should look like this: Now you have completed designing the interface, we need to start putting some blocks in to give it the functionality required.

Step 3: Add the functionality to the Interface Once the interface is ready we can set the functionality of the components. What we want to happen can be described in the following steps: 1. The user clicks the Scan button and scans a barcode with the phone s camera. 2. The application then searches Google with the result or opens the URL in a browser (if the QRCode is a URL). For this application we are going to need 2 user defined variables: buttonaction (value is 1 if URL has been scanned, and 0 otherwise), and barcoderesult (this will be the resulting string from the barcode/qrcode scan). Firstly drag 2 variable blocks onto the Blocks Editor screen from the Built-In > Definition menu. Rename the first buttonaction and the second barcoderesult. It should look as such: Now we will set the default values of these variables. In the menu drag a number block from the Built-In > Math and a text block from the Built-In > Text menu. Connect the number block to the buttonaction block, and connect the text block to the barcoderesult block. Then change the value of the number block to 0 and delete the text from the text block. The end result should look like this:

Now that we have the default values of our variables defined we must add functionality to the buttons. The first button we are going to add functionality to is the scanbutton. In the Blocks Editor, under the My Blocks menu there is an item called scanbutton, open this menu item and drag a scanbutton.click block onto the screen. Under My Blocks again, choose the call BarcodeScanner1.DoScan block from within the BarcodeScanner1 menu item and connect this inside the scanbutton.click block. The end result should look as such: This means that when the Scan button is clicked, the app will run the DoScan method of the BarcodeScanner which is all built into App Inventor. This will automatically perform a barcode scan from the phone s camera and return the result. So our next step is to be able to handle the result.

From the same menu again, under My Blocks > BarcodeScanner1 you will find a block titled; When BarcodeScanner1.AfterScan result do. Drag this onto the screen. Drag an ifelse block from Built-In under Control and insert this into the When BarcodeScanner1.AfterScan result do block. In the test argument of the ifelse block we are going to firstly check if the result is a number by using the built in call is a number?...thing block. This block is found under Math in Built-In.

The value that we would like to test is a number? is stored, as the result of the scan, in the variable defined as result. So from the My Blocks > My Definitions menu drag a result block onto the Blocks Editor and attach it to the call is a number?...thing block. Now, if the result is a number (which it should be if the barcode/qrcode is associated with a product) we want to carry out a series of actions. Firstly we want to inform the user that we have found a barcode number from the barcode. To do so we want to first change the text of the resultlabel. Inside the then-do section of the ifelse block we need to modify the resultlabel. To this block add a set resultlabel.text to block which can be found under My Blocks > resultlabel.

Now to make the information more user friendly, rather than just presenting the user with a number we will make the resultlabel text value more reader friendly with a join block. Drag a join block from the Built-in > Text menu and connect it to the set resultlabel.text to block. From the same menu also drag a text block to the first half of the join and to the second half, add a result block from My Blocks > My Definitions. Now edit the text block and replace the default text with; Found barcode:. The result should look like so: Beneath the set resultlabel.text to block we then want to modify the text of the action button. This will inform the user of the action the button would execute if pressed. To do so add a set resultactionbutton.text to block underneath and connect to this a text block found in Built-In > Text. Like so: Change the text in this text block to Search Google for product. As seen in the picture above.

Finally, we want to modify the global variable buttonaction and set it to 0. This is because the value of the barcode/qrcode is not a URL. To do so, underneath the set resultactionbutton.text to block add a set global buttonaction to block and connect to it a number block with the value of 0. Note: the set global buttonaction to block is found under My Blocks > My Definitions and the number block is under Built-in > Math. The end result should look like this: This is the first basic function of our scanner defined. If the app was put into operation now and a normal linear barcode was scanned on a product, the app would get the barcode number and change the resultactionbutton text to Search Google for product.

Next we must define the operation if the scanned barcode/qrcode has a URL stored in its data. As we are carrying out much of the same steps, and given that you should now be familiar with where the different blocks are, the next operation is a repetition of what we have just done. We want another copy of every block inside the red box. Somewhere else on the Blocks editor page, construct a copy of everything within this red box before we modify it. Like so: Now as this time we are not looking for a barcode number but instead a URL we must change some of the blocks and values, but the overall structure will stay the same.

Firstly we are no longer testing if the result is a number; we are now testing if the result is a web address. As all web addresses contain the prefix http:// we can test to see if this is in the information collected from the barcode/qrcode. To do this remove the is a number? block from the test area of the ifelse block like so: We will replace this with a block designed to test if text contains a sub-string. This block is the contains block, found under Built-In > Text. Connect this into where the is a number? block used to be. To this block, connect to the text part the result block we have on screen, and to the piece part connect a new text block with the value http://. The end result should look like so:

Now we need to modify a few of the previous text blocks to give information specific to URL s. In the text block attacted to set resultlabel.text to change the first text block to Found URL:. It will look like so: In the text block attached to set resultactionbutton.text to change the text to Visit URL in browser. It should look like this:

Finally change the number block attached to set global buttonaction to to 1. The end result, after all these steps, should be a segment of blocks like so: We want to slot this ifelse block, into the first ifelse block, within the else-do part. Drag your second elseif block and put it inside your first, the result will look like this:

Now, if we ran the app it would be able to cope with a barcode containing a product number and a QRCode containing a web address. The final function of a barcode\qrcode we must prepare for is a simple value. For this again we are just repeating steps that you have already done in this tutorial. Within the original ifelse statement we create a duplicate of blocks again, this time everything inside the original then-do part (as seen in red below). Duplicate all of these blocks again, in a separate section of the blocks editor. If should end up looking like this:

Now we want to modify these blocks to deal with simple values that can be stored in barcodes/qrcodes. Firstly change the text block, in the first half of the join block to Found value: it should end up looking like so: Next we want to modify the text block directly below this to read Search Google for result. And finally change the number button directly below this again to 0 (as seen below in red). The end result is this: Now drag all of this into the empty slot of your second ifelse block. The end result should be as seen on the next page.

At this stage the barcode/qrcode reader is setup to handle linear barcodes, QRCodes with URL s (web addresses) imbedded in them and simple values. The final thing that must be done inside this BarcodeScanner1.AfterScan method is to modify the barcoderesult global variable and set it to the result of the scan. To do this inside My Blocks > My Definitions drag 2 blocks to the screen; a set global barcoderesult to block and, a result block, attach these together (as seen below) and place them inside BarcodeScanner1.AfterScan below both ifelse blocks.

The final form of this block is: So at this point the app is capable of completely reading in the information in barcodes or QRCodes and modifying components on the screen. The last thing that has to be handled on the screen is what happens when the resultactionbutton is clicked.

From My Blocks > resultactionbutton, drag the when resultactionbutton.click do block onto the screen. Inside this we will place everything we want to happen when the resultactionbutton is clicked. This block will perform 2 different actions depending on the value (either 0 or 1) of buttonaction. These values represent whether the code scanned is either a web address (1) or just a barcode/value (0). Firstly we must use an ifelse block to perform different operations depending on buttonaction s value. Get an ifelse block from Built-In > Control and put it inside the when resultactionbutton.click do, it will look like this. Now the test value will be whether buttonaction is 0 or 1 first, so we will need 3 blocks here; buttonaction (from My Blocks > My Definitions ) Equals block (from Built-in > Math ) number block (from Built-in > Math ) change its value to 0

Once all three of these are on screen attach them as shown in the picture below to test the value of buttonaction within the if statement. Within the then-do part of the ifelse block we will define everything that we want to happen when buttonaction does equal 0 (i.e. when the data from the barcode is either a product barcode number or a value). We need to define a new activity on the phone (this is how we launch external applications from within our app, such as; browser, texts or emails. Before we start this activity we have to pass it all the information it will need on startup. The information it will need on startup is that it will be a new view on the screen (think of it like a new window opening up) which will be our browser, and the web address this browser is going to open. Pull onto the Blocks Editor screen these 7 blocks set ActivityStarter1.Action to (from My Blocks > ActivityStarter1 ) set ActivityStarter1.DataUri to (from My Blocks > ActivityStarter1 ) 2 x text blocks (from Built-in > Text ) join block (from Built-in > Text ) ActivityStarter1.StartActivity (from My Blocks > ActivityStarter1 ) barcoderesult (from My Blocks > My Definitions ) First take the set ActivityStarter1.Action to and attach it inside our ifelse block from before. Then attach one of the text blocks to the open part of the set ActivityStarter1.Action to block.

It will look like this: Now change the text in the text block you just connected and type: android.intent.action.view be very careful of your spelling and case here. It should look as such: This means that every time resultactionbutton is clicked and buttonaction equals 0 a new activity will start to be created and that this activity will be a VIEW (like a new window in the browser). Below the set ActivityStarter1.Action to block we now need to define the webpage that we will be visiting, this is where we will connect the set ActivityStarter1.DataUri to block.

It will then look like this: To this block we will firstly connect the join block. We need this join block because the DataUri we are defining here is what will be put into the address bar of the browser. So we need to form it properly to do a Google search. In the first half of the join block we put the pre-cursor to every Google search which is http://www.google.com/m?q=. You will notice no matter what you search for on Google this will be the start of the address in the address bar of your browser, followed by the words you are actually searching for. Thus we need to join this to the barcoderesult from our scan. So our barcoderesult will go in the other half of the join block. After these steps your block should look like this:

Now we have defined all the parameters we need to start a new browser window all that is left is to start the browser and show it on screen, this is done by the ActivityStarter1.StartActivity block and it is placed under the set ActivityStarter1.DataUri to block. Like so: The final section we have to do is the else-do part of the ifelse block, which defines what happens when the buttonaction variable does not equal 0 (i.e. equals 1 is already a web address). This is again a repeat of all of the previous steps so create a copy of all of the blocks seen below in the red box somewhere else on the Blocks Editor:

It should look like so: Now as this is still a webpage we are going to be going to the ActivityStart1.Action is still set to the same text, edit the text block attached to it and again enter android.intent.action.view. Now the DataUri value that is being passed to the activity is not as unorganised this time. As the data from the QRCode is already a web address we don t need to construct one by adding the Google pre-cursor. So within the ActivityStarter1.DataUri block we can just attach the barcoderesult block and delete the text and join blocks. The end result will look like this: This group of blocks is now completely capable of handling a QRCode that already contains a web address. Drag this group and place it inside the else-do part of the ifelse block, inside the resultactionbutton.click.

The final form will look like so: And that is your barcode/qrcode application complete. Well Done! That s it, the app is now ready for you to test it.

Step 4: Try it out Connect to the device and test the program Now connect your device (phone or tablet) to the PC, deploy the application to your device, and test the app as you have done in the other tutorials. You should be familiar with deploying apps to your device by this stage but if you have any complications, refer back to the previous tutorials, details can be found at the end of tutorials 1-8. ~ Have fun ~