Android Application Development CSE 55204520 Wireless Networks Outline

  • Slides: 46
Download presentation
Android Application Development CSE 5520/4520 Wireless Networks

Android Application Development CSE 5520/4520 Wireless Networks

Outline • Introduction to Android Applications • Setting up the Android application development Environment

Outline • Introduction to Android Applications • Setting up the Android application development Environment • Creating and Running Applications • Anatomy of ANDROID Applications

INTRODUCTION TO ANDROID APPLICATIONS

INTRODUCTION TO ANDROID APPLICATIONS

Introduction to Android Applications • Android is a mobile software platform (OS) from Google

Introduction to Android Applications • Android is a mobile software platform (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

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, 3 G, and Wi. Fi �Camera, GPS, compass, and accelerometer �Rich development environment

What is Dalvik VM (DVM)? • Dalvik is the process virtual machine (VM) that

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 Machinecompatible. class files to Dalvik-compatible. dex (Dalvik Executable) files before installation on a device.

Android Architecture

Android Architecture

Android API vs. Android SDK • Application Programming Interface (API) is an interface (set

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

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.

Platform Version Android 4. 1, 4. 1. 1 Android 4. 0. 3, 4. 0.

Platform Version Android 4. 1, 4. 1. 1 Android 4. 0. 3, 4. 0. 4 Android 4. 0, 4. 0. 1, 4. 0. 2 Android 3. 1. x Android 3. 0. x Android 2. 3. 4 Android 2. 3. 3 Android 2. 3. 2 Android 2. 3. 1 Android 2. 3 Android 2. 2. x Android 2. 1. x Android 2. 0. 1 Android 2. 0 Android 1. 6 Android 1. 5 Android 1. 1 Android 1. 0 API Level 16 15 14 13 12 11 10 VERSION_CODE JELLY_BEAN ICE_CREAM_SANDWICH_MR 1 ICE_CREAM_SANDWICH HONEYCOMB_MR 2 HONEYCOMB_MR 1 HONEYCOMB GINGERBREAD_MR 1 9 GINGERBREAD 8 7 6 5 4 3 2 1 FROYO ECLAIR_MR 1 ECLAIR_0_1 ECLAIR DONUT CUPCAKE BASE_1_1 BASE

SETTING UP THE ANDROID APPLICATION DEVELOPMENT ENVIRONMENT

SETTING UP THE ANDROID APPLICATION DEVELOPMENT ENVIRONMENT

Setting up the Android development environment 1. Download and install Java 6 (JDK 1.

Setting up the Android development environment 1. Download and install Java 6 (JDK 1. 6) 2. Download Eclipse (JEE, Classic or Java developers) 3. Download and install Android SDK base – – Download: http: //developer. android. com/sdk/index. html http: //developer. android. com/sdk/installing. html 4. Install Eclipse ADT Plugin (Android Development Tools in Eclipse) 5. Adding platforms and SDK components 6. AVD (Android Virtual Device)

Installing Android SDK • First download and install Android SDK • This is not

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 1. Start Eclipse, then select Help > Install New Software. 2.

Install Eclipse ADT 1. Start Eclipse, then select Help > Install New Software. 2. Click Add, in the top-right corner. 3. 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/ 4. Click OK. 5. In the Available Software dialog, select the checkbox next to Developer Tools and click Next. 6. In the next window, you'll see a list of the tools to be downloaded. Click Next. 7. Read and accept the license agreements, then click Finish. 8. When the installation completes, restart Eclipse.

Using SDK components • Run Android SDK manager – Window -> Android SDK Manager

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/addingpackages. html

Create an Android Virtual Device (AVD) • Defines the system image and device settings

Create an Android Virtual Device (AVD) • Defines the system image and device settings used by the Emulator • To create an AVD through Eclipse: 1. Select Window > Android SDK and AVD Manager. The Android SDK and AVD Manager displays. 2. Make sure the entry for Virtual Devices is selected and click New. 3. 4. 5. 6. 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.

DEVELOPING AND RUNNING APPLICATIONS

DEVELOPING AND RUNNING APPLICATIONS

Application Components • Activity ◦ Present a visual user interface for one focused endeavor

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

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 ◦

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

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

Usage of Intent to start an activity • Allows communication between components – Message passing – Bundle Intent intent = new Intent(Current. Activity. this, Other. Activity. class); start. Activity(intent);

Android “Hello World” • File New Project Android Application Project – Next time you

Android “Hello World” • File New Project 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

“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. your. Company. 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

“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 “Blank. Activity”

“Hello World” - Options for Blank Activity • Activity Name – Name of “main”

“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_name. • Navigation Type – For now, leave this as “None” • Hierarchical Parent – Parent Activity (for when user presses Up). Empty for now. • Title

Running New App on Emulator • Same as with any project • R-click Run

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

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 androiddir/platform-tools/ and run “adb devices”. Your device should now be listed.

Running App on Mobile Phone Cont. • In the Android device – Enable USB

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.

ANATOMY OF ANDROID APPLICATION

ANATOMY OF ANDROID APPLICATION

Anatomy of Android Application

Anatomy of Android Application

Android Manifest • Every application must have an Android. Manifest. xml file (with precisely

Android Manifest • Every application must have an Android. Manifest. 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

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.

Structure of the Manifest File

Structure of the Manifest File

Structure of the Manifest File Cont.

Structure of the Manifest File Cont.

Structure of the Manifest File Cont.

Structure of the Manifest File Cont.

The lifecycle of and Android Activity

The lifecycle of and Android Activity

Example • Create a network monitor using Android’s Traffic. Stats class http: //www. techrepublic.

Example • Create a network monitor using Android’s Traffic. Stats class http: //www. techrepublic. com/blog/appbuilder/create-a-network-monitor-usingandroids-trafficstats-class/774

More Android Samples • In Eclipse – File -> New -> Project… – Select

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 1. Logging smart phone activities or resource usage while an

Project 3 - Objectives 1. Logging smart phone activities or resource usage while an application is running 2. What are the resources available to monitor – Monitoring the resources requested and test it with one single application. 3. Download and test with a certain category of applications 4. 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 -

References • Android Developers - http: //developer. android. com/index. html • Android Tutorial - http: //www. coreservlets. com/android-tutorial/ • Dr. Lotzi Bölöni - http: //www. cs. ucf. edu/~lboloni/Teaching/EEL 6788_2010/ • Dr. Lotzi Bölöni (slides)- http: //www. cs. ucf. edu/~lboloni/Teaching/EEL 6788_2010/slides/T 8 a. Android. Tutorial. ppt • Dr. Natasa Przulj - http: //www. doc. ic. ac. uk/~natasha/course 2012/docs/android-tutorial. pdf