App Development 103 Manual Guide
App Development 103 Manual Guide
DEVELOPMENT
103 MANUAL
Objective: By the end of this course, students should
be able to:
Learn about the how to access websites with links from their
mobile application. They will understand links and text
encryption
Build a Call and messaging app, a utility app that can be used
to make calls and send text messages, as well as select contacts
from the contact list
There are many times when you want an app to behave in a random
or irregular way. For example, you might want a character in a game
to move in an unpredictable way. In this simple example, you’ll
simulate a dice roll on your phone—the user shakes the phone to see
a new random number. At this stage, you’ll just display a number;
later you’ll make the result look more like an actual dice.
APP RATING
As you can see, you plug the random integer block into a set
[Link] block and then plug it all into an
[Link] event trigger. There you have it
the simplest app you’ve made since Hello World! and now you
know how to make a random whole number. If you ever need a
random fraction for something, there’s a sister block to random
integer called random fraction that doesn’t need a high and low
value it generates a random number between 0 and 1.
2. Taking it further
The Dice Roll app is one of the simplest in the book. The next app is
the most complex you’ve made so far. It brings together everything
you’ve learned about variables and random numbers, plus we’ll add
some new ideas like using procedures that make your code more
efficient and explore the idea of validation. You’ll also learn how to
watch variables while the app is running to make sure they’re doing
what you expected.
This app takes a message you type and turns it into a secret code.
The app lets you send the coded message by SMS text to one or
more of your agents (or friends) from your phone’s Contacts list.
Your fellow agents can decode the message by copying and pasting
it into their own version of the app.
APP RATING
ASSETS YOU’LL NEED
Image: [Link]. Sounds: coding_completed.mp3 and
message_sent.mp3.
Warning!
Before you start this app, you need to know that sending messages
may cost money and this app can send lots of messages all at once.
Check with whoever pays your mobile phone bill to be sure this is
OK. You can test the app without sending messages; we’ll tell you
how as you work through it.
1. Setting up the screen
Depending on your phone, you may find that the list of agents the
user selects overlaps the image of the key (on the screen
background). You can improve this by putting AgentsLabel into a
VerticalArrangement so it’s contained in a column on the left of
the screen.
This app is for fun, and the code can be easily cracked; but real
computer programmers are paid to figure out how to send secret
messages that can’t be read even if they’re intercepted. This isn’t
just for secret agents—whenever you buy something online, you
want to be sure that only you and the online shop have your personal
payment details.
Look back at the three types of loops that we showed you earlier in
the chapter. Which kind makes the most sense here? Before you run
the loop, you do know how many times it should run: the same as
the number of characters in the message. App Inventor can tell you
the number of letters in any text string using a block called length in
the text section. So, you can use a for range loop. Step 1 says you
start at the end of the message and work backward, so you need the
for range start value to be the length of the message. You’re
working back to the first letter, so the end value needs to be 1 and
because you’re working backward, you set the step value to -1, like
this:
The do part of the loop needs to perform step 2a: “Write down the
current letter.” In programming terms, you set up a variable called
CodedMessage and keep joining the current letter to it as you run
through the loop. The segment block lets you extract any part of a
text string. In this case, you want to extract a single letter at the
current position or loop counter. Once the loop is complete, you’ll
change the MsgTextBox to show the new encrypted message, and
you’ll also play a sound so the user notices that the coding has
finished. Here are the final blocks:
Try it now. A single button click encrypts the message; clicking the
button a second time decrypts the message. Next you need to figure
out how to send the message to a list of contacts.
Letting the user delete an agent from the lists is a two-step process.
First you need to fill the DeletePicker list picker with all the agents
the user has selected so far, to give them a choice of whom to delete.
Then, when they pick an agent, you need to delete that agent’s name
from AgentNames and their telephone number from AgentTels.
Then, to delete the agent from the two lists, you can use the
SelectionIndex of the agent the user chose from the onscreen list.
You also need to update the onscreen label so the user knows the
agent is no longer selected:
Before you start this section, remember that sending messages may
cost money and this app can send lots of messages all at once!
Check with whoever pays your mobile phone bill to be sure this is
OK. You can test the app by leaving out the texting block call
[Link] until you’re sure the rest of the app is
working perfectly.
1. Here’s the basic idea broken into steps. When the user clicks
SendButton ...
2. Set the text message to be whatever the coded message says (we
have this stored already in the variable CodedMessage).
3. For each agent in the AgentTels list:
a) Set the texting phone number to that agent’s number.
b) Send the SMS text message.
4. Once all the SMS texts have been sent, play a confirmation sound
and display a notification message.
You’ve already seen that App Inventor lets you connect with other
people using text messages. In this chapter, we’ll look at other tools
that let you send and receive information, this time using the internet.
You’ll see how you can show pages from websites, read information
from online sources, and store data in the cloud using the WebDB
component.
App Inventor offers two options for viewing the World Wide Web:
1. WebViewer component—This option displays web pages in
your app. The WebViewer uses a mini browser that is part of
App Inventor. It doesn’t have lots of functions like you might be
used to in Chrome, Firefox, Safari, or any of the many other
browsers you can use. But it’s fine if all you want to do is browse
and navigate some web pages.
2. ActivityStarter component—This option jumps out of your
app and displays web pages in a web browser installed on your
phone. Using ActivityStarter allows the user to view the web
page in whichever app they choose, so they get all the functions
they’re used to. It’s also possible for you to provide no choice of
app and to specify exactly which app should be used but if the
user doesn’t have the app on their phone, it may cause an error
(so we don’t recommend doing that). The user returns to your
app by quitting the web browser app.
Using WebViewer
To set up the components for a WebViewer test, follow these steps:
1. Set up a new app, and call it TestWebViewer.
2. Set [Link] to “WebViewer Example” and
[Link] to Landscape.
3. Add a HorizontalArrangement with five buttons, as shown:
It’s also possible to change the current web page in the blocks using
the GoToUrl block. In the example, we’ve set the web page to the
App Inventor home page by hard-coding the web address into a text
block. You could just as easily include a text box in the app as an
address bar and use whatever the user types into it as the input for
[Link]. Now let’s look at the more flexible
ActivityStarter component.
Using ActivityStarter
To set up the components for an ActivityStarter test, follow these
steps:
1. Set up a new app, and call it TestActivityStarter.
2. Set [Link] to “ActivityStarter Web Browser Example”.
3. Add a Button, an ActivityStarter (from the Connectivity Palette
group), and a Notifier (from the User Interface Palette group).
4. Set the ActivityStarter properties as shown next.
From this sequence, you can work out that the [Link] event
opens the Notifier, and then the [Link] event
triggers the ActivityStarter. Here are the blocks:
Your app should now launch a web browser successfully give it a try.
ActivityStarter is versatile and can launch other apps such as the
camera, Google Maps, and even other apps you’ve written. Also, if
you enter a URLto a specific resource related to an app, Android will
present more options in the app list. For example, if you have the
YouTube app installed and you use a YouTube URL, then you’ll
have the option to view the video in your browser or YouTube app.
There’s full documentation about how to do this on MIT’s App
Inventor website here: [Link]
API keys
Most public APIs ask you to apply for a key to use the API—you
provide an email and some other details, and you get a key (which is
actually a code) sent back. You don’t have to do this for web-
page browsing so what’s the difference? When you request a web
page, it’s sent to your machine, and then you spend some time
reading it before you ask for the next page. This doesn’t put much
strain on the web servers (the computers that hold the web pages).
With APIs, you’re using a computer (smartphone) to request data—
and computers can make lots of requests quickly. If your computer
got stuck in a loop and made too many requests too quickly, the web
server might crash. An API key limits the number of requests any
one computer can make in a certain time, so you can’t crash the
servers.
CALCULATOR APP
Calculator application
Screen1 properties Title: Calculator app
Background color:
Black
Component What do I name it? What does it do? What property do I set?
Horizontal Calculator screen The space that Shows |Height: 80px
arrangement the expressions you Width: fill parent
input Align horizontal: center
Align horizontal:center
Align vertical: center
Horizontal Horizontal Contains the buttons |Height: 90px
arrangement arrangement 1,2,3 and divide Width: Fill parent
Color: None
Button Button1 The number of the | Height: Fill parent
button Width: 70px
Text color: White
Text:1
Font bold: yes
Fontsize:40px
After building the front view, this is what your app should look like.
1. Programming the blocks
Make a global variable for the decimal point and name it decimal_point
Drag and drop the decimal button, if decimal button is clicked bring in
an if then statement. If global decimal_point is true then set
decimal_point to true. Drag and drop an if the else statement. If global
first_numer is equal to an empty string then set global first number to
join global first number else join global second number to global
second number. call the matimatical expression
Division button
When the division button is clicked, set the operator to the division
symbol, call the procedure and set global decimal_point to false. Repeat
the multiplication, addition, and subtraction block
Equal Button
When the equal button is clicked, drag and drop your If then block. We
will compare if global operator is equal to addition then set the answer
label text to the first number + the second number. Drag and drop else if
for the minus, addition, division and multiplication. If our operator is
subtraction, set the answer label to first_number – second_number, If
our operator is addition, set the answer label to first_number +
second_number, If our operator is multiplication, set the answer label to
first_number x second_number, If our operator is 0, set the answer label
to invalid operation. Else set the answer label to global first_number
divided by global second number.
Set global first_number to answer text, set global operator to an empty
text, set global second number to an empty text and set the decimal
points to False.
Clear Button
When clear button is clicked,
Set global first_number to an empty text
set global operator to an empty text
set global second_number to an empty text
call the mathematical expression I.e the procedure
set answer label to an empty text
TO-DO LIST APP
The To-do list app helps us keep tract of our activities and also
saves them so we don’t have to lose them when needed. It is more
effective, efficient and reliable than the hard copy notepad.
To-Do List
Screen1 properties Title: To-Do List
Background color:
Grey
Component What do I name it? What does it do? What property do I set?
Label Enter your name Gives information |Height: Automatic
Width: Fill parent
Text: Enter Your To Do
List Item
Textbox To-do textbox |Height:Automatic
Width: Fill parent
Color: White
Button SubmitButton Used to submit the list |Height:Automatic
Width: Automatic
Color: Black
Text: SUBMIT
Webviewer Webviewer Accesses the internet |Height: Automatic
Width: Automatic
Listview Listview Views list |Height: Fill parent
Width: Fill parent
Checkbox Checkbox |Height:Automatic
Width: Fill parent
TidyDB TinyDB Stores data |Height: 15%
Width: Fill parent
Notifier Notifier Used to display Color: Black
information Length: Long
Creating a list
A list can be used to save data just like our variables and TinyDB
component but what differentiates the list from the tinyDB
component and Variable is that the list is a temporary storage site,
which means it can’t hold data for long while the TinyDB and
Variable is a permanent storage site, which means it can hold more
data for a longer period of time.
The TinyDB component saves and retrieves items when that has
been save. We call this feature the Getters and Setters of the
TinyDB. When saving a file to the TinyDB component, the item has
to be tagged, more like giving it a name for easy recovery or
accessibility.
Remember I told you that our list can serve as a storage site but only
temporarily, if we want to save up data permanently then we can use
the TinyDB.
Saving out data is one thing, retrieving them and displaying them in
an orderly fashion is another thing. For our to-do list items to be
displayed properly, we are going to use our Listview. The Listview
takes all the items in the list (both the previously saved items and the
just added items), arranges and displays them on our Display Label
so the user can see.
Finally, we will be clearing the text our TextBox so the user can
input a new item.
Confirm deleting an item
In order to delete an item from our list, the CheckBox has to be
checked/ mark indicating that you want to delete an item. One could
mistakenly click on the CheckBox without having the intentions of
deleting any item, so to seek confirmation that the user wants to
delete an item we will have our Notifier ask the user. If the user feel
they don’t want to delete the item again, the app should provide an
option to enable them leave safely without tampering on any save
item. Otherwise, if the user confirm deleting the item by clicking on
YES, then it is taken away.
Know that the Notifiers only pops when the CheckBox has been
checked and we are deleting the item from our Listview.
Deleting an item
When a user clicks an item to be deleted, an event is raised from the
Notifier and the users choice (YES or cancel) is going to be saved
to the notifier in the choice parameter. After picking, if the user’s
choice is YES, we can specify which item needs to be deleted from
the index number on the list. An index is the position of an item in a
list. When the user has deleted the item, our TinyDB should update
the list with the remaining item not deleted and arrange them orderly
with their index number.