Android Programming with App Inventor
Sensing the World Using Sensors
Sensors, true to their names, are the eyes and ears of your Android device. They allow your device to sense the world around it. For example, the location sensor on your device keeps track of your current location information using your mobile and Wi-Fi signal information and GPS data. Other sensors on your Android device include proximity sensors and motion sensors. In this section, let's use the location sensor on your Android device to write two simple applications that can be used on their own or as a starting point for something more useful and customized. In the process, you'll learn to make use of a couple more App Inventor components.
E-mail Your Current Location
Consider a not-so-fictional scenario when you might want to tell your friend exactly where you are at the moment so that she can drive down to meet you. Or, you simply may be lost. Either way, the Location Sensor can help. Let's call this project "LocationOnClickEmail". The user interface for this project looks like the one shown in Figure 5. Besides the basic components, such as text labels and buttons, add the LocationSensor component (found under the Sensors category) and an ActivityStarter component (found under the Other Stuff category). The ActivityStarter component, which has been named "MailAppStarter" will be used to start the e-mail application on the Android device. For details on the ActivityStarter Component, refer to http://appinventor.mit.edu/learn/reference/other/activitystarter.html.
Figure 5. User Interface for the LocationOnClickEmail Project
Now you need to add the project logic using the Blocks Editor as before. Figure 6 shows the final state of the Blocks Editor for this project.
Figure 6. Final Blocks for the LocationOnClickEmail Project
The application logic can be divided into two steps—obtaining the location using the Location Sensor when the Get Location button is clicked. This is done in the "when GetLocationButton.Click" code block. When this button is clicked, the Location Sensor is enabled. Once the Location Sensor has been able to obtain the location information, it invokes the "when LocationSensor1.LocationChanged" method where the text labels are updated with the location data. Next, when the Email Location button is clicked, the MailAppStarter component's DataUri property is set to start the mailing application. Here, the recipient is set to "droidery@gmail.com", the subject to "My Location" and the body of the message to the obtained address. The recipient and subject can be changed in the mailer application on the device.
That completes the current project. For more details on using the Location Sensor and the App Starter components, refer to the App Inventor Reference (see Resources).
Text-Messaging-based Location Sensor Application
In the last application, you initiated the location sending event. What if you want to design an application that will run as a service, such that when it receives a request via text message, it sends your current location to the sender? Even with privacy being such a sensitive issue in today's connected world, such an application can be useful if you want to make sure your not-so-grown-up kid isn't lost, for example. In addition to the Location Sensor component, you will become familiar with the Texting component in this application.
Here is the idea: on receipt of a text message with "location" in its body, the application replies with the current location as a text message. The actions taken upon receipt of a text message are shown in Figure 7. This is the core logic for the application. In the "Texting1.MessageRecieved" procedure, the "number" and "messageText" are available as arguments. If the "messageText" is "location", then check whether the location has been obtained. If yes, then construct a reply using the address and send the text; otherwise, send an error message back as the reply.
Figure 7. Action Taken When a Text Message Is Received
The complete application, along with others, can be downloaded from https://bitbucket.org/amitksaha/articles_code/src. You can upload the source (.zip) archives to App Inventor directly and try out the applications after packaging them. In this article, I have strictly concentrated on using an Android device for testing the applications. For basic uses, you also can use the emulator that is available in App Inventor and also use a live development methodology where you can install the application directly to your device. See the App Inventor Web site to try these out. I tested these applications on my Samsung Galaxy-SII running Android 2.3, but I hope there won't be any issues with running them on other devices running Android 2.2 and higher.
Looking Ahead
I started this article with the intention of having some fun programming for the Android platform, and I hope it has been so thus far. If you're interested in looking into App Inventor further, the first things that you might want to check out, apart from extending the projects to something more fun and useful, are the various other components. Of special note is the Data Store component that allows you to store data on the device, the Web components for interacting with remote Web content, other Sensor components and Media components.
App Inventor is fun, but you might feel that although it's good as a starting point, you would prefer a more traditional programming language as you become more familiar with Android development. Instead of completely throwing your App Inventor project away, consider using the App Inventor Java Bridge to use your App Inventor components while you write Android applications using the more traditional way of programming in Java.
If you feel the need to run your own App Inventor service, the MIT Center for Mobile Learning has made available the App Inventor JARs to enable you to host your own service (see Resources).
If you want to keep exploring App Inventor itself, two excellent books are available: David Wolber, Hal Abelson, Ellen Spertus and Liz Looney's App Inventor: Create your own Android apps (O'Reilly) and Jason Tyler's App Inventor for Android: Build Your Own Apps—No Experience Required! (Wiley).
If you enjoyed App Inventor, you might want to look at some other tools for programming your Android device visually, such as DroidDraw and Corona. And if you want to program Android visually on the device itself, check out Catroid.
Resources
MIT App Inventor: http://appinventor.mit.edu
Setting Up Your Computer: http://appinventor.mit.edu/learn/setup/index.html
App Inventor Reference: http://appinventor.mit.edu/learn/reference/index.html
APK File Format: http://en.wikipedia.org/wiki/APK_%28file_format%29
Under the Hood of App Inventor: http://googleresearch.blogspot.com/2009/08/under-hood-of-app-inventor-for-android.html
App Inventor Open-Source Project: http://code.google.com/p/app-inventor-releases
Activity Starter Component: http://appinventor.mit.edu/learn/reference/other/activitystarter.html
App Inventor Java Bridge Project: http://groups.google.com/group/app-inventor-instructors/browse_thread/thread/10a64e64b7886afb
Running Your Own App Inventor Service: http://appinventoredu.mit.edu/developers-blogs/andrew/2011/nov/running-your-own-app-inventor-service
App Inventor Course: http://sites.google.com/site/appinventorcourse
"Android App Development" presentation by Peter McNeil: http://www.cjugaustralia.org/September+2011
Catroid Project: http://code.google.com/p/catroid
Code for This Article (available in the appinventor_article subdirectory): https://bitbucket.org/amitksaha/articles_code/src
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Tech Tip: Really Simple HTTP Server with Python
- BASH script to log IPs on public web server
3 hours 27 min ago - DynDNS
7 hours 3 min ago - Reply to comment | Linux Journal
7 hours 35 min ago - All the articles you talked
9 hours 59 min ago - All the articles you talked
10 hours 2 min ago - All the articles you talked
10 hours 3 min ago - myip
14 hours 28 min ago - Keeping track of IP address
16 hours 19 min ago - Roll your own dynamic dns
21 hours 33 min ago - Please correct the URL for Salt Stack's web site
1 day 44 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
android dev
Great android tutorial. I'm new in Android Programming but I need learn more to be good android apps developer. I also learn basic android Programming here >> http://akiavintage.com/android/android-programming/, and many ebook you can download there http://akiavintage.com/ for android dev.
I like android
It's very informative and helpful.
This is why i like android it
This is why i like android it always come up with something new and interesting.
I actually think there is a
I actually think there is a better application for creating Android apps? Maybe there's a few...
App inventor
App inventor seems to be a nice service for developing applications. I have been working in an android application development company as a developer and made a few nice apps. Truly speaking the work is a head ache but it seems like app inventor may reduce my work load.
Thanks for sharing.
mabel
Hello. I wanted to drop you a quick note to verbalize my thanks. I've been watching your blog for a month or so and have picked up a heap of good information as well as enjoyed the way you’ve structured your site. I am undertaking to run my own blog however I think its too general and I would like to focus more on smaller topics..
http://www.wegotsoccercleats.com/
hi
wow I am very impressed by your post, it contains very relevant information and tip. google android apps
very good post, i certainly
very good post, i certainly love this website, keep on it
nice share
App inventor is certainly a great tool to use.
Thanks for sharing the information
Thanks for sharing the information, It's very informative and helpful. and serasa
I really like this blog is a
I really like this blog is a great pleasure to read something new and interesting .
App creator
This is great! As for the last comment coders have produced plenty of poor programs. This will give non coders a chance to produce some fresh ideas.
Isn't it because of such
Isn't it because of such tools that the Android market is polluted by so many crappy applications?