Download It
Transcript of Download It
![Page 1: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/1.jpg)
Rung-Hung GauDepartment of Computer Science and Engineering
National Sun Yat-Sen University
Kaohsiung, Taiwan
1
Introduction to Google Android
![Page 2: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/2.jpg)
2
![Page 3: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/3.jpg)
3
![Page 4: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/4.jpg)
Outline
4
What you get from AndroidAn Android Application is a
Loosely-Coupled Software SystemThe Project StructureThe Manifest File
![Page 5: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/5.jpg)
What you get from Android
5
You get a commonly-used programming language (Java)
some commonly used libraries (e.g., some Apache Commons APIs),
support for tools you may be used to (Eclipse)
![Page 6: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/6.jpg)
What you get from Android
6
You get a fairly rigid framework in which your programs need to run and do not interfere with other programs or the operation of the phone itself
![Page 7: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/7.jpg)
What you get from Android
7
Storagedatabases or files
NetworkAndroid devices will generally be Internet-
readyRaw Java sockets available Built-in WebKit-based Web browser (as
Safari) widget you can embed in your application
![Page 8: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/8.jpg)
What you get from Android
8
Multimediaplay back and record audio and video.
GPSAndroid devices will frequently have access
to location providers
Phone Servicesinitiate calls by programssend and receive SMS messages
![Page 9: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/9.jpg)
An Android Application is a Loosely-Coupled Software System
9
ActivitiesContent ProvidersIntentsIntent Receivers/Broadcast Receiver
Services
![Page 10: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/10.jpg)
Activities
10
The building block of the user interface.
The Android analogue for the window or dialog in a desktop application.
![Page 11: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/11.jpg)
Content Providers
11
Content providers provide a level of abstraction for any data stored on the device that is accessible by multiple applications.
The Android development model encourages you to make your own data available to other applications.
![Page 12: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/12.jpg)
Intents
12
Intents are system messages, running around the inside of the device, notifying applications of various events, hardware state changes (e.g., an SD card was inserted),
incoming data (e.g., an SMS message arrived),
application events (e.g., your activity was launched from the device's main menu).
![Page 13: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/13.jpg)
Intents
13
You can receive and respond to intents by intent filtersintent/broadcast receivers
You can create your own intents to launch other activities, let you know when specific situations arise (e.g., raise an intent when the user gets within 100 meters of a specified location)
![Page 14: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/14.jpg)
Services
14
Activities, content providers, and intent receivers are all short-lived and can be shut down at any time.
Services are long-lived and can be independent of activities.
![Page 15: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/15.jpg)
Services
15
You might use a service for checking for updates to an RSS feedplaying back music even if the controlling activity is no longer operating.
![Page 16: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/16.jpg)
Overview of a Project
16
The Android build system is organized around a specific directory tree structure for your Android project, much like any other Java project.
![Page 17: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/17.jpg)
Items in the project's root directory:
17
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 script for compiling the application and installing it on the device
default.properties: a property file used by the Ant build script
![Page 18: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/18.jpg)
Items in the project's root directory:
18
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
![Page 19: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/19.jpg)
Items in the project's root directory:
19
res/: holds "resources", such as icons, GUI layouts, and the like, that get packaged with the compiled Java in the application
assets/: hold other static files you wish packaged with the application for deployment onto the device
![Page 20: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/20.jpg)
When you create a project
20
When you created the project, you supplied the fully-qualified class name of the "main" activity for the application (e.g., edu.nsysu.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/edu/nsysu/android/SomeDemo.java).
![Page 21: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/21.jpg)
When you compile a project
21
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).
![Page 22: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/22.jpg)
The “res” directory
22
This directory holds "resources" – static files that are packaged along with your application
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 specificationsres/menu/ for XML-based menu specificationsres/raw/ for general-purpose files (e.g,. a CSV file
of account information)res/values/ for strings, dimensions, and the likeres/xml/ for other general-purpose XML files you
wish to ship
![Page 23: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/23.jpg)
The “bin” directory
23
When you compile your project (via ant or the IDE), the results go into the bin/ directory under your project root:bin/classes/ holds the compiled Java classesbin/classes.dex holds the executable created
from those compiled Java classesbin/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)
![Page 24: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/24.jpg)
The “bin” directory
24
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 emulator,
or -unsigned indicating that you built your application for release (ant release), but the APK still needs to be signed using jarsigner and an official key.
![Page 25: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/25.jpg)
25
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=“edu.nsysu.android"> <uses-permissionandroid:name="android.permission.ACCESS_LOCATION" /> <uses-permissionandroid:name="android.permission.ACCESS_GPS" /> <uses-permissionandroid:name="android.permission.ACCESS_ASSISTED_GP
S" /> <uses-permissionandroid:name="android.permission.ACCESS_CELL_ID" /> <application> .../* activities, intent filters, broadcast receivers, services
and etc */ </application></manifest>
![Page 26: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/26.jpg)
On The Manifest File
26
The root of all manifest files is a manifest element.
The biggest piece of information you need to supply on the manifest element is the package attribute.
Here, you can provide the name of the Java package that will be considered the “base“ of your application.
Then, everywhere else in the manifest file that needs a class name, you can just substitute a leading dot as shorthand for the package.
![Page 27: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/27.jpg)
On The Manifest File
27
For example, if you needed to refer to edu.nsysu.android.search.Snicklefritz in this manifest shown above, you could just use “.Search.Snicklefritz”, since com.commonsware.android is defined as the application's package.
![Page 28: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/28.jpg)
More Elements
28
uses-permission elements (requires your own application): to indicate what permissions your application
will need in order to function properlypermission elements (requires other
applications): to declare permissions that activities or
services might require other applications hold in order to use your application's data or logic
![Page 29: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/29.jpg)
More Elements
29
instrumentation elements: to indicate code that should be invoked on
key system events, such as starting up activities, for the purposes of logging or monitoring
uses-library elements:to hook in optional Android components,
possibly a uses-sdk element: to indicate what version of the Android SDK
the application was built for an application element
![Page 30: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/30.jpg)
The Children of The Application Element
30
The real meat of the manifest file are the children of the application element.
By default, when you create a new Android project, you get a single activity element.
This element supplies android:name for the class implementing the
activity,android:label for the display name of the activity, an intent-filter child element describing under
what conditions this activity will be displayed.
![Page 31: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/31.jpg)
The Children of The Application Element
31
The stock activity element sets up your activity to appear in the launcher, so users can choose to run it.
You can have several activities in one project and each activity corresponds to a “phone screen”.
![Page 32: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/32.jpg)
32
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=“edu.nsysu.android.skeleton"> <application> <activity android:name=".Now"
android:label="Now"> <intent-filter> <action
android:name="android.intent.action.MAIN" /> <category
android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
![Page 33: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/33.jpg)
Intent Receivers
33
You may also have one or more receiver elements, indicating non-activities that should be triggered under certain conditions, such as when an SMS message comes in. These are called intent receivers.
![Page 34: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/34.jpg)
Content Providers
34
You may have one or more content providers – components that supply data to your activities and, with your permission, other activities in other applications on the device.
These wrap up databases or other data stores into a single API that any application can use.
![Page 35: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/35.jpg)
Services
35
You may also have one or more services – long-running pieces of code that can operate independent of any activity.
The quintessential example is the MP3 player, where you want the music to keep playing even if the user pops open other activities and the MP3 player's user interface is hidden.
![Page 36: Download It](https://reader036.fdocuments.net/reader036/viewer/2022081602/55549a85b4c905fd608b4627/html5/thumbnails/36.jpg)
Reference
36
Reto Meier, Professional Android Application Development, 2009, Wrox, USA.
Mark L. Murphy, The Busy Coder's Guide to Android Development , 2009, CommonsWare, LLC., USA.