+ All Categories
Home > Software > Android Programming

Android Programming

Date post: 06-Jan-2017
Category:
Upload: yong-heui-cho
View: 510 times
Download: 0 times
Share this document with a friend
12
Android Programming Yong Heui Cho @ Mokwon University
Transcript
Page 1: Android Programming

Android Programming

Yong Heui Cho @ Mokwon University

Page 2: Android Programming

2

Context• Interface to global information

about an application environment• Uses of context– Creating new objects– Accessing standard common

resources– Accessing components implicitly

Activity

Context

OS

Page 3: Android Programming

3

Access of Context• this– Activity extends Context

• View.getContext()– Context for View (usually Activity

Context)• Activity.getApplicationContext()– Permanent Application Context

• ContextWrapper.getBaseContext()– Access to another Context

Page 4: Android Programming

4

Bundle vs. Parcel• Bundle– A mapping from String values to various

Parcelable types

• Parcelable– Interface for classes whose instances can be

written to and restored from a Parcel

• Parcel– Container for a message (data and object

references) that can be sent through an IBinder

Page 5: Android Programming

5

ContactsContract• Contract between the contacts

provider and applications• Context.getContentResolver()• Cursor: interface of results for

database query

Content Provider

Contacts Provider

Activity

Context

OS

getContentResolver()

ContactsContract

Page 6: Android Programming

6

Telephony Manager• Access to the telephony APIs is managed by

the Telephony Manager.– Monitor phone state– Retrieve incoming phone numbers– Observe changes to data connections, signal

strength, and network connectivity

Page 7: Android Programming

7

PhoneStateListner• Monitors changes in specific telephony

states on the device, including service state, signal strength, message waiting indicator (voicemail).

Activity

Context

PhoneStateListener

OS

TelephonyManager

listen()

Page 8: Android Programming

8

Incoming Phone Calls• Service

– an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use

• IntentFilter– Structured description of Intent values to be matched– Context.registerReceiver(BR, IntentFilter)– Context.unregisterReceiver(BR)

Activity

Context

OS

Service

broadcastIntent

BroadcastReceiver brTx

Context

registerReceiver() with IntentFilter

Page 9: Android Programming

9

Receiving Call• Permission–<uses-permission

android:name="android.permission.READ_PHONE_STATE" />Activity

Context

OS

Service

Intent

PhoneStateListener rxListener

Context

TelephonyManager

listen()

Page 10: Android Programming

10

Sending SMS• SmsManager

–  SmsManager.getDefault().sendTextMessage(phoneNum, null, msg, piSent, piDelivered);

• PendingIntent– a description token for a foreign application to allow the

foreign application to use our application's permissions– Action → Intent → PendingIntent(for broadcast)

Activity

Context

BroadcastReceiver brSend

OS

SmsManager

broadcastBroadcastReceiver

brDeliever

registerReceiver() with IntentFilter

PendingIntent

Page 11: Android Programming

11

Receiving SMS• Receiving process

– Broadcast → Intent → Bundle → PDU (Object[]) → SmsMessage → String

• Bundle: a mapping (or dictionary) class from String key to various types

• PDU: Protocol Description UnitActivity

Context

BroadcastReceiver brReceive

OS

SmsManager

Intent via broadcast

registerReceiver() with IntentFilter

Page 12: Android Programming

12

Bluetooth Setup• BluetoothAdapter (my device)• BluetoothDevice (partner devices)• void onActivityResult(int requestCode, int resultCode,

Intent data)• Parcelable Intent::getParcelableExtra(String)

Activity

Context

BroadcastReceiver brBluetooth

My OS

BluetoothAdapter- getDefaultAdapter()- isEnabled()- startDiscovery()- cancelDiscovery()

Intent via broadcastregisterReceiver() with IntentFilter

BluetoothDevice- getName()- getAddress()

Partner OS

Bluetooth


Recommended