Building your first app (Part 2): Completing HelloPurr
Now that you've set up your computer and device, and you've learned how the Designer and the Blocks Editor work, you are ready to complete the HelloPurr app. At this point, you should have the Designer open in your browser, the Blocks Editor open in another window, and your chosen device (phone or emulator) connected to the Blocks Editor.
Here's a preview of the steps you'll do in this tutorial to complete the app:In the Designer:
- Add a Label component that reads "Pet the Kitty".
- Upload the meow.mp3 file
- Add a Sound component that plays the meow.mp3 file.
- Create an event handler that tells the Sound component to play when the user taps the button.
Adding the label
- Drag and drop the Label component to the Viewer , placing it below the kitty. It will appear under your list of components as Label1
- Change the Text property of Label1 to read "Pet the Kitty". You'll see the text change in the Designer and on your device.
- Change the BackgroundColor of Label1 by clicking on the box
- Change the TextColor of Label1
- Change the FontSize of Label1 to 30
Adding the meow sound
- Click on the header marked Media to expand the Media section of the palette of components.
- Drag out a Sound component and place it in the Viewer . Wherever you drop it, it will appear in the area at the bottom of the Viewer marked Non-visible components .
- Click Add...
- Upload the meow.mp3 file to this project.
- For the Sound1 component, set its Source to meow.mp3.
Making the sound play
Using the Blocks Editor we will define how the app is going to behave. We'll tell the components what to do, and when to do it. You're going to tell the kitty button to play a sound when the user taps it. If components are ingredients in a recipe, you can think of blocks as the cooking instructions.
The Blocks Editor has two tabs on the upper left hand corner: Built-in and My Blocks . The buttons under each tab expand and expose blocks when clicked. The Built-in blocks are the standard set of blocks that are available for every app you build. The blocks under My Blocks contain specific blocks that are tied to the set of components that you have chosen for your app.
To make the sound play, you'll need to drag and drop the Button1.Click block and the Sound1.Play block into the editor. The blocks connect together like puzzle pieces.
Steps for making the sound play
- Navigate to the Blocks Editor . It may be covered up by the web browser.
- Click the My Blocks tab at the top left hand side.
- Click Button1 .
- Drag and drop the when Button1.Click do block onto the editor.
- Click Sound1 .
- Drag the call Sound1.Play block onto the editor and drop it into the when Button1.Click do block.
- Click the kitty picture on your device. You should hear the kitty meow.
Packaging your app
Congratulations, your first app is running! If you're using a phone, then the app is running on the phone, but it runs only while the phone is connected to App Inventor. If you unplug the USB cord, the app will vanish. You can reconnect the phone to make it come back. To get an that app runs without being connected to App Inventor, you must "package" the app to produce an application package (apk file). Pressing Package for Phone at the upper right of the designer page will present three options for packaging:
- If the phone is connected, you can download and automatically install the app on your phone.
- You can download the app to your computer as an apk file, which you can distribute and share as you like, and manually install on phones using the Android ADB program.
- You can generate a Barcode, which you can use to install the app on your phone with the aid of a barcode scanner, like the ZXing barcode scanner (freely available in the Android Market). This barcode works only for your own phone. If you want to share the app with others, you'll need to download the apk file to your computer and share the file.
Here are the key ideas covered so far:
You build apps by selecting components (ingredients) and then telling them what to do and when to do it.
You use the Designer to select components. Some components are visible and some aren't.
You can add media (sounds and images) to apps by uploading them from your computer.
You use the Blocks Editor to assemble blocks that define the components' behavior
when ... do ... blocks define event handlers , that tell components what to do when something happens.
call ... blocks tell components to do things.
Now that your computer is set up and you know the basics of how App Inventor works we recommend you:
- Complete additional Tutorials .
- Review the Reference Documentation .
- Join the User Discussion Forum .
- If you've been using the emulator and want to start using your phone, you can set up your Android phone to build apps.
Something not working right? Visit the troubleshooting page , or check the App Inventor User Forum for help.