Caution

Just as Android-based cell phones are not required to include a camera, they are not required to include GPS hardware either, although many models likely will include both a camera and GPS hardware. Android included the Android Location-Based API in anticipation that GPS hardware will be included in many cell phones. Because you are working on a software-based emulator, and not on a real device, the presence of GPS hardware has to be simulated. In this case, Android provides a file in the adb...

Configuring the Android Emulator for GTalk

Before you can begin coding this project, you need to adjust a development setting on the Android Emulator, XMPP Settings. With the project open, you need to depart from your routine for a minute. If you are familiar with GTalk, you are aware that you can use the product only when you log into your Google account. Therefore, you must take an extra step now to ensure that your device (in this case, the Android Emulator) can log into your Google account, thus enabling you to send and receive...

Note

While you may or may not encounter this exact error, depending on what release of the Android SDK is available when this book is published, you should follow the troubleshooting steps presented here, because they will help you in later projects. This error seems to point to the fact that my classes, somehow, are missing from the HelloWorldCommandLine.apk file. I can easily remedy this issue without using any of the Android SDK command-line tools. As it turns out, .apk files are just .zip files....

Rhisl Use Text View and Image View

Use some of the skills and techniques that you learned in this chapter to create a new Hello World application. Create an application that uses both the TextView and the ImageView to put an image on the screen with a text caption. This is slightly more difficult than using just one View on an Activity. Play with the Views and see what you can create. The next chapter takes one more look at Hello World applications, from the perspective of command-line programming. Q Does Android have a label or...

Editing Android Manifestxml

Take a look at the following AndroidManifest.xml file for the FindAFriend project. You need to add several Intent Filters for new Activities, including ones to edit a friend's location, edit a friend's name, and launch your Google Map. Also, pay close attention to the actions within each Intent Filter. These represent actions that will be passed to each Activity handling that Intent. Finally, do not forget to add Access_Location and Access_GPS permission so that you can add your current...

Adjusting the Permissions Level

The first step in working with the Android Location-Based API is to adjust the permissions level. Using the Android Location-Based API itself does not require any specific permission, but using the Android Location-Based API to access location information on the GPS does. There are two ways you can set the permission from Eclipse. The first is through the Android Manifest Permissions wizard, which you used in Chapter 7. In Eclipse, double-click AndroidManifest.xml to open the Android Manifest...

Ask the Expert

Q Eclipse is used to develop applications in Java, but can Android run applications written in any other languages As of the writing of this book, there were no other SDKs or emulators available to allow Android development in any language other than Java. Can you use Eclipse (and the Android SDK) with a version of the JRE other than version 5 Technically you can use Eclipse with versions 5 and newer. However, the latest version of Eclipse was only tested on the Java 5 JRE. Companies. Click...

Open Handset Alliance and Android

This barrier to application development began to crumble in November of 2007 when Google, under the Open Handset Alliance, released Android. The Open Handset Alliance is a group of hardware and software developers, including Google, NTT DoCoMo, Sprint Nextel, and HTC, whose goal is to create a more open cell phone environment. The first product to be released under the alliance is the mobile device operating system, Android. (For more information about the Open Handset Alliance, see...

Creating the FindAFriend Activity

To begin this section, create two files, findafriend.xml and FindAFriend.java. Once again, these files will hold your layout and code for the current section, respectively. The layout file is very basic and contains only a TextView. This TextView will be used to write results to in your list of friends. The full findafriend.xml file should appear as follows < xml version 1.0 encoding utf-8 > < TextView android paddingLeft 2 7dip The full contents of the FindAFriend.java file follows. All...

Downloading the Android SDK

The Android SDK is easily accessible from the http code.google.com android page. From the development home page, click the Download the SDK link under Getting Started. After you agree to the terms of the Android SDK License Agreement, you will see the Download the Android SDK page. The Android SDK is downloaded in a 79MB (for Windows) package and it should download fairly quickly. Click the package name for your operating system to begin the download. There is no setup or installation process...

Compiling and Installing the Application

You can now compile your command-line project. To compile your project, use ANT. Once the project is compiled, you will install it on your Emulator. After you have your JAVA_HOME environment variable set and have ANT in your PATH statement, you should be able to navigate the directory containing your build.xml file and simply run the command ant. Open a Windows command prompt to your project directory and run ant, as follows HB C Wi ii dow5 iyste in 3 m d, ejfe-...

Rhisl Toggling Between Map Views Standard and Satellite Views

Edit the AndroidLBS Activity one more time. You should add two more buttons to the RelativeLayout. These buttons should toggle the MapView between standard view and satellite view. Here are some points to consider Add the toggle buttons to the opposite corners of the MapView using the align layout attributes. Research the MapView to find the toggling method. Create a function that you can pass the MapView to and toggle it. The complete text of solution main.xml and AndroidLBS.java are as...

Creating the Activity for Auto Complete

In this section, you are going to create an Activity that will show off the AutoCompleteTextView. AutoCompleteTextViews can be very powerful tools for your applications. This View is specifically helpful at making the most of the limited space available to the Android main screen. AutoCompleteTextView, as the name implies, is a modified TextView that will refer a possible value for the completion of a word or phrase typed into it. Such Views are greatly useful in mobile applications when you do...

Editing Activity Permissions

Most Activity Action Intents fall into the category of requiring that the proper permission be set before Android will allow the action. As with many systems, Android just needs to make sure that only Activities with the correct credentials be allowed to perform actions with Activities that are outside of their base. Here are the available permissions BROADCAST_PACKAGE_REMOVED CHANGE_COMPONENT_ENABLED_ STATE SYSTEM_ALERT_WINDOW WRITE_CONTACTS WRITE SETTINGS Compare this list of permissions with...

Creating a SQLite Database

Android devices will ship with an internal SQLite database. The purpose of this database is to give users and developers a location in which to store information that can be used in Activities. If you have used Microsoft SQL Server or SQLite, the structure and process for using Android's SQLite database will not seem foreign. Whatever your experience, this section covers all the skills you need to create and use a fully functional SQLite database. You are going to create a database on your...

Android Debug Bridge Commands

The following commands are gsm commands. You access them by connecting to the Emulator's terminal console. If you do not know the port terminal console, it is one less than the debug port. Execute adb devices to get a list of active devices and the related port numbers. Prints dumpsys, dumpstate, and logcat data to the screen, for the purposes of bug reporting Simulates an inbound phone call from lt phonenumber gt Cancels an inbound phone call from lt phonenumber gt adb -d lt ID gt lt...

Using the Dialer

Now that you know what an Intent is, it is time to see one in action. This section shows you how to use the DIAL_ACTION Intent to open the phone dialer. You will pass a telephone number with your Intent. If your application works correctly, you should see displayed in the dialer the number you pass with your Intent. The first step is to create a new project for this Activity see Chapter 5 for instructions . Name the project AndroidPhoneDialer. The following illustration shows the New Android...

Implementing the ViewOnClick Listener

You need to modify the GoogleAPI class to implement the View.OnClickListener. This will allow you to call the onClick method from the Activity's main class when any button is clicked. Normally, this way of implementing the onClick method is only effective when you have numerous buttons on one Activity and want to handle all the onClick calls in one method. However, I felt that you should still see how the method works so you can use it in your own future code. Keep in mind that I am showing...

Adding Zoom Controls

For your last exercise in this chapter, you will add two more buttons to your AndroidLBS Activity. These buttons will control the zoom in and zoom out methods of the Google MapView. What makes this modification a little different is that I will introduce a new type of layout for your main.xml file the RelativeLayout. Whereas LinearLayouts allow you to place Views directly, one after the other, RelativeLayouts let you place Views on top of each other. For this Activity, you will be placing the...

Creating a Custom Content Provider

Android uses Content Providers to mitigate access to data. You used a Content Provider in Chapter 9 to access and read coordinate information from a GPS. The same process applies to databases. There are Content Providers for Contact Lists, IMs, and Recent Calls. However, there is not yet a Content Provider for your Friends database. Android is extremely flexible and allows you to create your own custom Content Providers for your own custom data. In this section you will create a Content...

Application Find a Friend

Click here for terms of use. Create a custom Content Provider Retrieve items from a database and pass them to a Google Maps Overlay This is the final chapter in which you will create an application, but it will be one of the largest applications introduced in this book. I will cover a couple of topics that you have not encountered thus far, and you will use the skills introduced in those topics to create a very robust application. In this chapter, you will learn how to create SQLite...

Creating the Friends Map Activity

The FriendsMap Activity is the final Activity that will be callable from the main application. This Activity will call your recordset from the Friends database and draw a circle on a Google Map for each friend. The Activity will also draw a circle for you at your current location. You need to begin by adding two new files to your project, friendsmap.xml and FriendsMap.java. Because you have seen the layout for the friendsmap.xml file in Chapter 9, there is no need to fully explain it here. You...

Android Viewsjava

The last step to create this Activity is to edit the AndroidViews.java. If you want to call the testEditText Activity from the main AndroidViews Activity, you must add code to the AndroidViews.java. Compare the following code with that in your current AndroidViews.java. Add the needed code to complete your file. package import android.app.Activity import android.os.Bundle import android.view.Menu import android.content.Intent public class AndroidViews extends Activity Called when the Activity...

Android Emulator Commands

The following table contains a list of the most common Android Emulator commands. These are the commands that were available as of the March 2008 SDK release. A short description is provided with each command. Enables the console shell on the current terminal Uses a different file as the working user-data disk image Flashes keypresses on the device skin Prints a list of all Emulator commands Makes all TCP connections through a specified HTTP HTTPS proxy Uses lt file gt as the system image Uses...

Rhisl Modify the Android PhoneDialer Project

If you played around with the latest version of the AndroidPhoneDialer, you may have noticed something missing. Unfortunately, the way the project is currently written, it allows you to input any type of value into the EditText View and try to send it to the Call Activity. This is really not an optimal approach to application development. Do some research and add some validation to the EditText. Use the following parameters to modify your project Use a regular expression to validate that a...

Passing Coordinates to Google Maps

In this section, you will build on the Activity you created in the previous section. The major modification you will make to your AndroidLBS Activity is to pass the coordinates to Google Maps. You will use Google Maps to display the user's current location. The only change you need to make to your main.xml file is to add a layout for the MapView. In the current version of the Android SDK, the MapView is established as a generic View. Perhaps in a future release there will be a MapView that...