1. Trang chủ
  2. » Giáo án - Bài giảng

Broadcast receiver document

27 531 0

Đ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

Định dạng
Số trang 27
Dung lượng 452,25 KB

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

Nội dung

Android CourseObjectives • After completing this module, you will able to: • Create Broadcast Intent.. • Broadcast messages between components with the sendBroadcast method.. • Listen to

Trang 2

Android Course

Objectives

• After completing this module, you will able to:

• Create Broadcast Intent.

• Broadcast messages between components with the sendBroadcast method.

• Listen to user Broadcast Intent.

• Listen to Native Broadcast.

2

Trang 5

Android Course

Using Broadcast Intent to send broadcast

Intent i = new Intent();

i.setAction( "com.btloc.android.demo.simplebroadcast" );

i.putExtra( "MESSAGE_KEY" , "Simple message" );

sendBroadcast(i);

5

Trang 6

Android Course

Broadcast Receivers

• Listen to Broadcast Intents.

• Must be registered (either in code or within the application manifest).

• Use Intent Filter to specify which Intents it is listening for.

6

Trang 7

Android Course

Listening to Broadcast Intent

@Override

// TODO Auto-generated method stub

String msg = intent.getStringExtra( "MESSAGE_KEY" );

Log.d( "onReceive" , msg);

} }

7

Trang 9

Android Course

Registering Broadcast Intent in code

Trang 10

Android Course

Native Broadcast

• ACTION_CAMERA_BUTTON – The camera button has been pushed.

• ACTION_TIMEZONE_CHANGED - The setting for the time zone has changed.

• ACTION_BOOT_COMPLETED – The boot progress has been completed

• ACTION_BATTERY_LOW - A warning that the battery is low.

• ACTION_HEADSET_PLUG - A headset has been plugged into the device, or unplugged from it.

• ACTION_SCREEN_ON - The screen has been turned on.

10

Trang 11

Android Course

Case Study for Native Broadcast

• Call Blocker Application

• Using android.intent.action.PHONE_STATE

• SMS blocker Applcation

• Using android.provider.Telephony.SMS_RECEIVED

11

Trang 12

Context context = null ;

12

Trang 13

Log.d( TAG , "Receving " );

TelephonyManager telephony = (TelephonyManager) context getSystemService(Context TELEPHONY_SERVICE );

13

Trang 14

telephonyService = (ITelephony) m.invoke(telephony);

for (int i = 0; i < blockedNumbers.length; i++){

e.printStackTrace();

} }

}

14

Trang 15

package name must be com.android.internal.telephony FileName : ITelephony.aidl

Trang 18

Android Course

SMSBlocker App – Step 1: Define SMSReceiver

SmsMessage.createFromPdu(( byte []) pdus[0]);

String phoneNumber = msg.getOriginatingAddress();

abortBroadcast();

} }

} } }

18

Trang 20

Android Course

Questions or Discussions

20

Trang 21

Android Course

References & Further Readings

• Intents and Intent Filters:

• http://

developer.android.com/guide/topics/intents/intents-filters.html

• Android App Course:

• Intents, Intent Filters, Broadcasts, Broadcast Receivers:

• http:// sites.google.com/site/androidcoursearchive/lectures

21

Trang 22

Android Course

References & Further readings

• Professional Android 2 Application Development , Reto

Meier, Wiley Publishing (2010)

• Intents, Broadcast Receivers, Adapters, and the Internet , Chapter 5

• Map, Geocoding, and Location-based Services , Chapter 8

• Working in the background , Chapter 9

• Telephony and SMS , Chapter 12

• Bluetooh, Network, and Wi-fi , Chapter 13

22

Trang 23

Android Course

References & Further Readings

• Android™ Wireless Application Development Second Edition , Shane

Conder, Lauren Darcey,

Addison-Wesley Professional Publishing (2010)

• Using SMS , Chapter 16

• Working with Wi-Fi , Chapter 19

• Monitoring the Battery , Chapter 19

23

Trang 24

Android Course

References & Further Readings

• Android in Practice 1 Edition ,

Charlie Collins, Michael D Galpin, and Matthias Kaeppler, Manning

Trang 25

Android Course

References & Further Readings

• Pro Android 3 , Mark Murphy,

Apress Publishing (2011)

• Building and Consuming Services , Chapter 11

• Exploring Handlers , Chapter 13

• Broadcast Receivers and Running Services , Chapter 14

Long-• Exploring the Alarm Manager , Chapter 15

• Exploring Maps and based Services , Chapter 17

Location-• Using the Telephony APIs , Chapter 18

25

Trang 26

26

Trang 27

Android Course

References & Further Readings

• Learning Android , Marko

Gargenta, O'Reilly Media

Publishing (2011)

• Broadcast Receivers , Chapter 11

• System Services , Chapter 13

27

Ngày đăng: 02/02/2015, 11:13

TỪ KHÓA LIÊN QUAN

w