for audio note-taking.

GPS

Android devices will frequently have access to location providers, such as GPS, that can tell your applications where the device is on the face of the Earth. In turn, you can display maps or otherwise take advantage of the location data, such as tracking a device’s movements if the device has been stolen.

Phone Services

Of course, Android devices are typically phones, allowing your software to initiate calls, send and receive SMS messages, and everything else you expect from a modern bit of telephony technology.

CHAPTER 2

Project Structure

The Android build system is organized around a specific directory tree structure for your Android project, much like any other Java project. The specifics, though, are fairly unique to Android and what it does to prepare the actual application that will run on the device or emulator. Here’s a quick primer on the project structure to help you make sense of it all, particularly for the sample code referenced in this book, which can be found in the Source Code area of the Apress Web Site at http://apress.com.

Root Contents

When you create a new Android project (e.g., via the activitycreator script, which you will see in Chapter 4, or an Android-enabled IDE), you get several items in the project’s root directory:

• AndroidManifest.xml, an XML file describing the application being built and what components — activities, services, etc. — are being supplied by that application

• build.xml, an Ant[5] script for compiling the application and installing it on the device

• default.properties, a property file used by the Ant build script

• bin/ holds the application once it is compiled

• libs/ holds any third-party Java JARs your application requires

• src/ holds the Java source code for the application

• res/ holds resources, such as icons, GUI layouts, and the like, that get packaged with the compiled Java in the application

• assets/ holds other static files you wish packaged with the application for deployment onto the device

The Sweat of Your Brow

When you create an Android project (e.g., via activitycreator), you supply the fully-qualified class name of the “main” activity for the application (e.g., com.commonsware.android.SomeDemo). You will then find that your project’s src/ tree already has the namespace directory tree in place, plus a stub Activity subclass representing your main activity (e.g., src/com/commonsware/android/SomeDemo.java). You are welcome to modify this file and add others to the src/ tree as needed to implement your application.

The first time you compile the project (e.g., via ant), out in the “main” activity’s namespace directory, the Android build chain will create R.java. This contains a number of constants tied to the various resources you placed out in the res/ directory tree. You should not modify R.java yourself, letting the Android tools handle it for you. You will see throughout many of the samples where we reference things in R.java (e.g., referring to a layout’s identifier via R.layout.main).

The Rest of the Story

As already mentioned, the res/ directory tree holds resources — static files that are packaged along with your application, either in their original form or, occasionally, in a preprocessed form. Some of the subdirectories you will find or create under res/ include

• res/drawable/ for images (PNG, JPEG, etc.)

• res/layout/ for XML-based UI layout specifications

• res/menu/ for XML-based menu specifications

• res/raw/ for general-purpose files (e.g., a CSV file of account information)

• res/values/ for strings, dimensions, and the like

• res/xml/ for other general-purpose XML files you wish to ship

We will cover all of these and more in later chapters of this book, particularly Chapter 19.

What You Get Out of It

When you compile your project (via ant or the IDE), the results go into the bin/ directory under your project root, specifically:

• bin/classes/ holds the compiled Java classes

• bin/classes.dex holds the executable created from those compiled Java classes

• bin/yourapp.ap_ holds your application’s resources, packaged as a ZIP file (where yourapp is the name of your application)

• bin/yourapp-debug.apk or bin/yourapp-unsigned.apk is the actual Android application (where yourapp is the name of your application)

The .apk file is a ZIP archive containing the .dex file, the compiled edition of your resources (resources.arsc), any un-compiled resources (such as what you put in res/raw/) and the AndroidManifest.xml file. It is also digitally signed, with the -debug portion of the filename indicating it has been signed using a debug key that works with the

Вы читаете Beginning Android
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату