500 likes | 1.02k Views
Android Application Development. CSE 5520/4520 Wireless Networks. Outline. Introduction to Android Applications Setting up the Android application development Environment Creating and Running Applications Anatomy of ANDROID Applications. Introduction to Android Applications.
E N D
Android Application Development CSE 5520/4520 Wireless Networks
Outline • Introduction to Android Applications • Setting up the Android application development Environment • Creating and Running Applications • Anatomy of ANDROID Applications
Introduction to Android Applications • Android is a mobile softwareplatform (OS) from Google and the Open Handset Alliance. • It is powered by the Linux Kernel • The underlying OS is written in C or C++ • But applications are built using Java • Built-in Apps = Apps created in SDK • Is an open source platform • Thus third party can add functionalities and does not have to rely on Google (ex: Multimedia Codecs, Sophisticated shell environment , etc.)
Android Features • Reuse and replacement of components • Dalvik virtual machine • Integrated browser • Optimized graphics • SQLite – DB owned by each application (can be shared) • Media support • GSM Telephony • Bluetooth, EDGE, 3G, and WiFi • Camera, GPS, compass, and accelerometer • Rich development environment
What is Dalvik VM (DVM)? • Dalvik is the process virtual machine (VM) that runs the apps on Android devices. • DVM is optimized to run on slow-cpu, low-ram, and low-power devices • Every Android application runs in its own process, with its own instance of the DVM • DVM is written so that a device can run multiple VMs efficiently • Programs are commonly written in Java and compiled to bytecode. • Then they are converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files before installation on a device.
Android API vs. Android SDK • Application Programming Interface (API) is an interface (set of libraries) that allows you to communicate with the Android platform. • Android Standard Development Kit (SDK) provides you the API libraries and the developer tools necessary to build, test and debug apps for Android.
What is an API Level? • API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform. • The framework API consists of: • A core set of packages and classes • A set of XML elements and attributes for declaring a manifest file • A set of XML elements and attributes for declaring and accessing resources • A set of Intents • A set of permissions that applications can request • Each successive version of the Android platform can include updates to the Android application framework API that it delivers.
Setting up the Android development environment • Download and install Java 6 (JDK 1.6) • Download Eclipse (JEE, Classic or Java developers) • Download and install Android SDK base • Download: http://developer.android.com/sdk/index.html • http://developer.android.com/sdk/installing.html • Install Eclipse ADT Plugin (Android Development Tools in Eclipse) • Adding platforms and SDK components • AVD (Android Virtual Device)
Installing Android SDK • First download and install Android SDK • This is not the complete SDK environment. • It includes only the core SDK tools, which you can use to download the rest of the SDK packages (such as the latest system image). • The installer will check for machine requirements and then saves the Android SDK Tools into a default location (or you can specify the location). • Make a note of the name and location of the SDK directory • you will need to refer to this directory later, when setting up the ADT plugin and when using the SDK tools from the command line.
Install Eclipse ADT • Start Eclipse, then select Help > Install New Software. • Click Add, in the top-right corner. • In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location:https://dl-ssl.google.com/android/eclipse/ • Click OK. • In the Available Software dialog, select the checkbox next to Developer Tools and click Next. • In the next window, you'll see a list of the tools to be downloaded. Click Next. • Read and accept the license agreements, then click Finish. • When the installation completes, restart Eclipse.
Using SDK components • Run Android SDK manager • Window -> Android SDK Manager • Probably prompted automatically after installing ADT plugin and restarting Eclipse • Select all entries, except that you can omit Android versions older than 2.2 • Click “Install n packages” • Runs for a long time • Detailed instructions • http://developer.android.com/sdk/installing/adding-packages.html
Create an Android Virtual Device (AVD) • Defines the system image and device settings used by the Emulator • To create an AVD through Eclipse: • Select Window > Android SDK and AVD Manager. The Android SDK and AVD Manager displays. • Make sure the entry for Virtual Devices is selected and click New. The Create new AVD window displays. • Enter a Name for the AVD. • Select Google APIs (API level 9) as the Target. • Click Create AVD. • Close the Android SDK and AVD Manager.
Application Components • Activity • Present a visual user interface for one focused endeavor the user can undertake • Example: a list of menu items users can choose from
Application Components Cont. • Services • Run in the background for an indefinite period of time • Example: calculate and provide the result to activities that need it
Application Components Cont. • Broadcast Receivers • Receive and react to broadcast announcements • Example: announcements that the battery is low
Application Components Cont. • Content Providers • Store and retrieve data and make it accessible to all applications • Example: Android ships with a number of content providers for common data types (e.g., audio, video, images, personal contact information, etc.) • Intents • Activities, services, and broadcast receivers — are activated by asynchronous messages called intents. • Hold the content of a message • Example: convey a request for an activity to let the user edit some text
Usage of Intent to start an activity • Allows communication between components • Message passing • Bundle Intent intent = new Intent(CurrentActivity.this, OtherActivity.class); startActivity(intent);
Android “Hello World” • File New Project Android Android Application Project • Next time you can do File New Android Application Project • Fill in options as shown on next pages • Run the project (will be explained later) • R-click Run As Android Application
“Hello World” - Setting Project Options • Application Name • Shown in Play Store and Settings Manage Application List. Usually same as Project Name. • Project Name • Eclipse project name. Follow naming convention you use for Eclipse. Not used elsewhere. • Package name • Apps on a particular Android device must have unique packages, • so use com.yourCompany.project • Build SDK • The Android version used to build/compile your project. This can be any version (e.g., the most recent), but the safest option is to make it match the minimum SDK below. • Minimum Required SDK • The Android version that you want to run on. • For most phone apps, choose 2.3.3, since that is the most common version in use worldwide. For learning new features, use latest version.
“Hello World” - Setting Project Options Cont. • Configure Launcher Icon • To choose the picture displayed on the Android device, that, when clicked, launches the app. • Use defaults for development and testing. Just press “Next”. • Create Activity • Choose “BlankActivity”
“Hello World” - Options for Blank Activity • Activity Name • Name of “main” Java class. This is the class you will edit first. • Class name often corresponds to project name. • Layout Name • Base name of XML file in res/layout folder. • Used to give layout to app. Often just called “main”. • Will be referred to in main Java class with R.layout.layout_name. • Navigation Type • For now, leave this as “None” • Hierarchical Parent • Parent Activity (for when user presses Up). Empty for now. • Title • Text that will be shown on Android title bar.
Running New App on Emulator • Same as with any project • R-click Run As Android Application • NOTE: do not close emulator after testing. Emulator takes a long time to start initially, but it is relatively fast to deploy a new or a changed project to the emulator.
Running App on Mobile Phone • Deploying via USB Connection • Prereq: install drivers for Android device • Plug phone (or other Android device) into computer. • Recent OS’s might find drivers automatically. If not, download from device manufacturer. • See list at http://developer.android.com/tools/extras/oem-usb.html • After installation, plug in phone, then go to android-dir/platform-tools/ and run “adb devices”. Your device should now be listed.
Running App on Mobile Phone Cont. • In the Android device • Enable USB debugging • Allow unknown sources • Verify USB drivers are on computer • http://developer.android.com/tools/extras/oem-usb.html • Plug into computer via USB • In Eclipse • R-click app, Run As -> Android Application • If emulator is open, will be given a choice of which device to deploy to. • If emulator not open, will deploy to physical device automatically.
Android Manifest • Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. • The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. • Among other things, the manifest does the following: • It names the Java package for the application. The package name serves as a unique identifier for the application. • It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of.
Android Manifest • It determines which processes will host application components. • It declares which permissions the application must have in order to access protected parts of the API and interact with other applications. • It also declares the permissions that others are required to have in order to interact with the application's components. • It declares the minimum level of the Android API that the application requires. • It lists the libraries that the application must be linked against.
Example • Create a network monitor using Android’s TrafficStats class http://www.techrepublic.com/blog/app-builder/create-a-network-monitor-using-androids-trafficstats-class/774
More Android Samples • In Eclipse • File -> New -> Project… • Select Android -> Android Sample Project • Select the API Level • Select the desired sample and click finish (Ex: Snake)
Project 3 - Objectives • Logging smart phone activities or resource usage while an application is running • What are the resources available to monitor • Monitoring the resources requested and test it with one single application. • Download and test with a certain category of applications • What are the plots and graphs to produce the resources used across all the applications.
References • Android Developers - http://developer.android.com/index.html • Android Tutorial - http://www.coreservlets.com/android-tutorial/ • Dr. LotziBölöni - http://www.cs.ucf.edu/~lboloni/Teaching/EEL6788_2010/ • Dr. LotziBölöni(slides)- http://www.cs.ucf.edu/~lboloni/Teaching/EEL6788_2010/slides/T8a-AndroidTutorial.ppt • Dr. NatasaPrzulj - http://www.doc.ic.ac.uk/~natasha/course2012/docs/android-tutorial.pdf