• No results found

ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall

N/A
N/A
Protected

Academic year: 2021

Share "ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall"

Copied!
17
0
0

Loading.... (view fulltext now)

Full text

(1)

ECE 455/555

Embedded System Design

Android Programming

(2)

Fundamentals of Android Application

Java programming language

Code along with any required data and resource files are

compiled into an Android package, .apk file.

Android applications don't have a single entry point

for everything in the application

No main() function

Default entry when you click the application icon

Components can also be started by other applications

http://developer.android.com/guide/topics/fundame

(3)

Activating Components

Application components

Activities, services, broadcast receivers

Activated by an asynchronous message called

intent

Bind components at runtime

You can start an activity by passing an intent to

startActivity()

Specify the main entry of your program in this way!

You can start a service by passing an intent to

(4)

Analyzing HelloWorld Application

One of the standard entry

function: crate an activity

instance

Create an user interface and

set the text

Default function to setup the

user menu specified in class R

(5)

Manifest XML file

Applications must declare their components in a

manifest file

Before Android can start an application component, it

must learn that the component exists.

AndroidManifest.xml for each application

Declares the application's

components

Names any

libraries

the application needs to be linked

against

Identifies any

permissions

the application expects to be

(6)

The Manifest XML File of HelloWorld

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloandroid" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

The only

component

Similarly you can claim <service>, <receiver> and

<provider> within the <application> tag

(7)

The Manifest XML File of HelloWorld

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.helloandroid" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

Type of

action

Other action types: CALL, SYNC, BATTERY_LOW,etc

Being indicated as

application entry

http://developer.android.com/guide/components

/intents-filters.html

The platform

version used

(8)

More in the Manifest XML file

Application requirements

Using external sensor/devices

<uses-feature android:name="android.hardware.bluetooth" />

<uses-feature android:name="android.hardware.camera" />

Using Android library

<uses-library android:name="android.view.animation" />

Request permission

<uses-permission android:name="android.permission.CAMERA" />

More details at:

http://developer.android.com/guide/topics/manifest/manifes

t-intro.html

(9)

API Demos

Demonstrating how the

system API work

Import demo projects into

Eclipse

-> Android project from

existing code

\...\Android\android-

sdk\samples\android-10\ApiDemos

(10)

API Demos

Run the program as a Java application

It will automatically compile and upload the .apk file to the

phone

There will be an application named

“API Demos” on your phone

(11)

Sensing API Demo

In the API Demo menu, choose OS->Sensors

Application that displays the values of 3-axis acceleration

sensors graphically

Frequently used in games for

gravity detection!

implementation

com.example.android.apis.os

(12)

Sensing API Demo

Access sensor readings through SensorManager class

Get an instance of SensorManager

Listen sensor readings when the

application is active at foreground

(13)

Sensing API Demo

Read and convert sensor readings

Implemented as an

event handler

Readings of 3D

orientation sensors

Otherwise, use

accelerator data

Reading conversions

(14)

Sensing Related Packages

Media

http://developer.android.com/reference/android/media/p

ackage-summary.html

Location

http://developer.android.com/reference/android/location/

package-summary.html

Hardware

http://developer.android.com/reference/android/hardwar

e/Sensor.html

(15)

Thoughts…

Can you realize fancier functionalities based on the

sensing capabilities provided by Android?

All the codes you need are included in the samples!

Check \...\Android\android-sdk\samples\android-10\

Integrating sensing capabilities with other

applications

(16)

Summary

Android: an open-source operating system for

smartphones

Micro-kernel, middleware-based OS implementation

Each application runs in Java virtual machine

Expensive but reliable and secure

Application

Java programming enabled

Components: activity, service, content provider, broadcast

receiver

Configured by Manifest XML file

Sensing capabilities of smartphones

(17)

Other Smartphone Platforms

Doing your project on your own smartphones or

tablets

iPhone, BlackBerry, iPad, etc.

A tutorial of iPhone programming can be found here.

http://www.edumobile.org/iphone/category/iphone-programming-tutorials/

http://web.eecs.utk.edu/~weigao/ece455/fall2015/iPhone

Development.zip

References

Related documents