LogCat Window
At the bottom of the Eclipse IDE there are by default a few
rectangular windows. One of the more
important ones is called the LogCat window, and this window
displays debug and error messages
that are directly coming from a program that is running on the
Android device that is attached to your
computer via a USB cable
Launching the SDK
Manager and AVD Manager from Eclipse
To launch the Android SDK Manager and the AVD Manager from within
the Eclipse IDE, click “Window”
in the top menu bar and use the menu items near the bottom of the
list. The SDK Manager enables
you to download new versions of the Android platform and other
tools to develop with. The AVD
Manager allows you to create and manage virtual Android devices
for the Android device emulator
Hands-on Example:
Non–OpenGL ES Text “Hello World”
Program
In
this hands-on example, we will create a new Android project that will output a
simple “Hello World”
text
string. Start up the Eclipse IDE.
The
first thing to do is to specify a work space where you will put this new
project. Select
File
➤
SwitchWorkSpace ➤ Other from the main Eclipse menu to bring up a pop-up
window in
which
you can select a directory that will serve as the current work space where new
projects will be
stored.
Use the Browse button on the pop-up window to navigate to the folder you want
to use as
the
work space, then hit the OK button to set this folder as your current work
space.
Creating a New Android
Project
To create a new Android project, select “Android Application
Project” under the File ➤ New menu
(see
Figure 1-16).
This will bring up a pop-up window in which you can specify your
application name, project name,
package
name, and SDK information (see Figure 1-17).
In the Application Name edit box, enter “RobsHelloWorld,” which is
the name of your application that
will appear to users of your program. In the Project Name edit
box, enter “RobsHelloWorld,” which is
the name of the project that is displayed in the Eclipse IDE.
Enter “com.robsexample.robshelloworld”
as the package name associated with this new Android project. This
package name must be unique.
For the Minimum Required SDK select Android 2.2 (Froyo), because
this is the lowest Android
platform that supports OpenGL ES 2.0. For the Target SDK, select
the highest Android platform API
that you anticipate to have successfully tested your application
against. For the Compile With list
box, select the API version that you wish to compile your
application for. You can leave the Theme
list box at the default value. Click the Next button to move to
the next screen.
The next thing to do is to configure the project. For this
example, just accept the default values and
click
the Next button (see Figure 1-18).
In the next screen, you can configure the launcher icon, if you
wish. However, for this example, you can
just
accept the defaults (see Figure 1-19).
Click the Next button. The next screen allows you to select the
type of activity you want to create.
Select
the Blank Activity and click the Next button (see Figure 1-20).
Accept the defaults for the blank activity. The default activity
name is “MainActivity.” The default
Layout Name is “activity_main,” and the default Navigation Type is
“None.” Click the Finish button to
create
the new Android application (see Figure 1-21).
On the left-hand side of the Eclipse IDE in the Package Explorer
window, you should see a new
entry called “RobsHelloWorld,” which is our new example program.
The key directories are the
“src” directory, where the Java source code is stored; the “libs”
directory, where external libraries
are stored; and the “res” directory, where resources such as
graphics, 3D models, and layouts are
stored. Under the “res” directory, the “layout” directory stores
the application’s graphical layout
specifications; the “menu” directory stores the applications
menu-related layout information; and
the “values” directory stores the actual “Hello World” string that
is displayed. Finally, a key file is
the AndroidManifest.xml file, which contains information about
permissions and other application
specific
information. (See Figure 1-22 for the layout of the “RobsHelloWorld” project.)
Running on an Android
Emulator
Before we run our example on the emulator, we must first set up an
Android Virtual Device. Select
Window ➤ Android Virtual Device
Manager from the Eclipse menu to start up the Virtual Device
Manager. Click the New button. Another window should pop up with
the heading “Create new
Android Virtual Device (AVD).” Enter a name for your virtual
device in the “AVD Name:” field. Select a
device to emulate and Target, as shown in Figure 1-23. Accept the default values for the rest of the
inputs.
Click the OK button.
Next, we have to run our example. If you are running this for the
first time, you will have to specify how
to run this application. Make sure the “RobsHelloWorld” project is
highlighted. Select Run ➤ Run from
the Eclipse main menu.
When the pop-up window appears, select “Android Application” and
click the OK button to run the
example. If you do not have an actual Android device attached to
your computer via USB cable,
Eclipse
will run the program on the Android emulator (see Figure 1-24).
The Android emulator should start by default and run our sample
program. The actual code for this
program
is shown later in this chapter (see Figure 1-25).
Running on an Actual Android
Device
In order to download and run the program on an actual Android
device, the device must be put
into USB Debugging mode. Press the Menu key, which is the
left-most key on the bottom portion
of an Android phone. Click the Settings button, then click the
Applications button and then the
Development button. Click the “USB Debugging” option. After doing
so, the item should be
checked,
as in Figure 1-26
Note On Android 4.0 and newer models,
the USB Debugging option is under the Settings ➤ Developer
options.
On Android 4.2 and newer models, the Developer options are hidden by default.
To make it available,
go
to Settings ➤
About Phone and tap the Build
number seven times. Return to the previous screen to find
Developer
options.
Next,
you have to install the appropriate USB software driver for your model of
Android phone onto
your
development system. Try to connect your Android device to your computer first,
to see if it
automatically
installs the correct drivers. If you can’t run the program on your device, then
you will
have
to install a device driver from the manufacturer. Usually the manufacturer of
your phone has
a
web site with downloadable drivers. After doing this, connect your phone to
your development
system, using a
USB cable, which most likely was included with your mobile phone.
Now you are ready to start using the device. Select Run ➤
Run from the main Eclipse
menu.
A window should appear in which you can choose to run the program
on an actual Android device or
an
Android Virtual Device (see Figure 1-27). Select the hardware device and click the OK button.
The program running on the device should be the same as depicted
in Figure 1-25. Press the Back
key
to exit the program.
Thank You,See You Next Post-Visit: theit-mela.blogspot.com
No comments:
Post a Comment