1. Trang chủ
  2. » Công Nghệ Thông Tin

6 - telephony apis và location base services apis

45 253 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề 6 - Telephony APIs và Location Base Services APIs
Trường học Ho Chi Minh University of Industry
Chuyên ngành Telephony APIs and Location Base Services APIs
Thể loại lecture notes
Thành phố Ho Chi Minh City
Định dạng
Số trang 45
Dung lượng 1,38 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

1.1 Working with Telephony Utilities Gaining Permission to Access Phone State Information  You can use the TelephonyManager object to retrieve the state of the phone and some informa

Trang 3

1.1 Working with Telephony Utilities

 If your application uses telephony features, make sure you set the <uses-feature> tag with the

android.hardware.telephony feature (or one of its sub-features) in your application’s manifest file to ensure

your application is installed only on compatible devices

Read more Hardware Features:

http://developer.android.com/guide/topics/manifest/uses-feature-element.html#hw-features

Trang 4

1.1 Working with Telephony Utilities

 Gaining Permission to Access Phone State Information

<uses-permission android:name=

"android.permission.READ_PHONE_STATE" />

You can use the TelephonyManager object to retrieve the state of the phone and some

information about the phone service itself, such as the phone number of the handset

Read more details:

http://developer.android.com/reference/android/telephony/TelephonyManager.html

Trang 5

5

Trang 6

1.1 Working with Telephony Utilities  Cont…

 Listening for changes in the call state can enable an application to react appropriately to

something the user might be doing For instance, a game might automatically pause and save

state information when the phone rings so that the user can safely answer the call

An application can register to listen for changes in the call state by making a call to the listen()

method of TelephonyManager

Trang 7

7

Trang 8

1.1 Working with Telephony Utilities  Cont…

Trang 9

1.1 Working with Telephony Utilities

 Get telephony service

Add the PhoneStateListener.LISTEN_SERVICE_STATE flag to the listener described earlier and

implement the onServiceStateChanged method, which receives an instance of the ServiceState object.

Trang 10

1.1 Working with Telephony Utilities  Cont…

Trang 11

1.1 Working with Telephony Utilities

 Working with Phone Numbers

The resulting output to the log would be the string “999-555-1212”

 Check the phone number is an emergency phone number by calling

PhoneNumberUtils.isEmergencyNumber()

Trang 12

1.1 Working with Telephony Utilities

 Working with Phone Numbers

The formatNumber() method can also take an Editable as a parameter to format a number in

place.The useful feature here is that you can assign the PhoneNumberFormattingTextWatcher

object to watch a TextView (or EditText for user input) and format phone numbers as they are

entered

Trang 14

1.2 Using SMS

 Sending an SMS

To send an SMS, an application first needs to get an instance of the SmsManager

final SmsManager sms = SmsManager.getDefault();

Now use sendTextMessage method:

sms.sendTextMessage(

"0987773061", null , "Hello!", null , null );

BUT the application does not know whether the actual sending of the SMS was successful without

providing a PendingIntent to receive the broadcast of this information

Trang 15

15

Trang 16

1.2 Using SMS

 Receiving an SMS

The application must register a BroadcastReceiver to listen for the Intent action associated with

receiving an SMS

(I made 2 examples in the chapter 4 – Multithreading & Service)

 Two ways to register a BroadcastReceiver

 In coding : using the registerReceiver method

In Manifest XML: using the receiver tag

Trang 17

pdus

Trang 18

1.2 Using SMS  By Manifest

Trang 19

1.2 Using SMS

 Reading SMS from Inbox

All available column names in SMS table:

[ _id, thread_id, address,

person, date, protocol, read,

status, type, reply_path_present,

subject, body, service_center,

locked, error_code, seen]

Using the ContentResolver to query SMS :

ContentResolver contentResolver = getContentResolver();

Cursor cursor = contentResolver.query(

Uri.parse( "content://sms/inbox" ),

null , null , null , null );

Trang 20

1.3 Making and Receiving Phone Calls

You can also use two emulator instances to test calling to another handset As with the SMS sending,

the port number of the emulator is the phone number that can be called

2 emulator

Trang 21

1.3 Making and Receiving Phone Calls

 Making Phone Calls

The Android SDK enables phone numbers to be passed to the dialer in two different ways:

 The first way is to launch the dialer with a phone number already entered.The user then needs to press the Send button to actually initiate the call.This method does not require any specific

permissions

 The second way is to actually place the call This method requires the

android.permission.CALL_PHONE permission to be added to the application’s

AndroidManifest.xml file.

Trang 22

1.3 Making and Receiving Phone Calls

 Making Phone Calls

Uri number = Uri.parse("tel:01656152042");

Intent dial = new Intent(Intent.ACTION_DIAL, number);

startActivity(dial);

Uri number = Uri.parse("tel:01656152042");

Intent call = new Intent(Intent.ACTION_CALL , number);

startActivity(call);

<uses-permission android:name=

Trang 23

1.3 Making and Receiving Phone Calls

 Receiving Phone Calls

An application can register to answer incoming phone calls To enable this in an application, you must implement a broadcast receiver to process intents with the action Intent.ACTION_ANSWER

You can use the CallLog.calls class to determine recent call information, such as

 Who called

 When they called

 Whether it was an incoming or outgoing call

 Whether or not anyone answered

 The duration of the call

Trang 24

1.3 Making and Receiving Phone Calls

 Receiving Phone Calls

Trang 25

1.3 Making and Receiving Phone Calls

 Receiving Phone Calls

Trang 26

1.3 Making and Receiving Phone Calls

Exercise 1: Write an application to manage Calls log

http://developer.android.com/reference/android/provider/CallLog.Calls.html

Exercise 2: Write an application to manage Blacklist (has GUI)

it is not possible to block incoming calls, if your application has no root privileges.

Trang 28

2.1 Using Global Positioning Services

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

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

Steps to determine device location:

1 Retrieve an instance of the LocationManager using a call to the

getSystemService() method using the LOCATION_SERVICE.

2 Add an appropriate permission to the AndroidManifest.xml file, depending on what type of location information the application needs

3 Choose a provider using either the getAllProviders() method or the getBestProvider() method

4 Implement a LocationListener class

5 Call the requestLocationUpdates() method with the chosen provider and the LocationListener object to start

receiving location information

Trang 29

2.1 Using Global Positioning Services

Click here to download KML for emulator:

https://

sites.google.com/site/mengyangc/blog/akmlsampleandroidkmlfileformockgpslocationtestonemulator

https:// developers.google.com/kml/documentation/mapsSupport

Trang 30

2.1 Using Global Positioning Services

Trang 31

31 2.1 Using Global Positioning Services

Trang 32

2.1 Using Global Positioning Services

Trang 33

33 2.1 Using Global Positioning Services

Trang 34

2.2 Geocoding Locations

According to the Android documentation, AVDs that target the Google APIs enable developers to test on emulator instances with the “Google experience.” The Google APIs provide the capability to use Google Maps as well as a backend geocoder service

The Geocoder object can be used without any special permissions, some methods:

getFromLocation

getFromLocationName

return List<Address>

Trang 35

35 2.2 Geocoding Locations

Trang 36

2.2 Geocoding Locations

Trang 37

37 2.2 Geocoding Locations

Trang 38

2.3 Mapping Locations

 The Android SDK provides two different methods to show a location with Google Maps:

The first method is to use a location Uri to launch the built-in Google Maps application with

the specified location

The second method is to use a MapView embedded within your application to display the

map location

Trang 39

39 2.3 Mapping Locations

Mapping Intents

Trang 40

2.3 Mapping Locations

Mapping Intents

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

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

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

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

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

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

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

Trang 42

2.3 Mapping Locations

Mapping Views

 Getting Your Debug API Key:

To use a MapView in your applications, you must obtain a Google Maps API Key from

Google.The key is generated from an MD5 fingerprint of a certificate that you use to sign your

applications

You need to do the following to generate the appropriate API key:

Trang 43

2.3 Mapping Locations

Mapping Views

 Getting Your Debug API Key:

1 Generate an MD5 fingerprint for your debug certificate

2 Sign in to http://code.google.com/android/maps-api-signup.html with a Google account

3 Accept the Terms of Service

4 Paste in the fingerprint from Step 1

5 Save the Android Maps API key presented on the next screen

Reading more:

https:// developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

Trang 44

2.3 Mapping Locations

Mapping Views

Some features in Mapview:

 Zooming the Map View

 Marking the Spot

Hint: Reading…

Page 206 – Android Wireless development (android 4.0)

Exercise for Mapping Views:

Write an application to support 2 features:

- Zooming the MapView

- and Marking the spot

Trang 45

45

Ngày đăng: 06/07/2014, 18:35

TỪ KHÓA LIÊN QUAN

w