intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình cho thiết bị di động: Chương 6 - ĐH Công nghê Đồng Nai

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:45

124
lượt xem
17
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Lập trình cho thiết bị di động: Chương 6 - Telephony APIs VÀ Location base services APIs có nội dung trình bày về Telephony APIs và LBS APIs. Tham khảo nội dung bài giảng để hiểu rõ hơn về các nội dung trên.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình cho thiết bị di động: Chương 6 - ĐH Công nghê Đồng Nai

  1. DONG NAI UNIVERSITY OF TECHNOLOGY API 1 2 Telephony LBS APIs APIs 1
  2. DONG NAI UNIVERSITY OF TECHNOLOGY 1. Telephony APIs 1.1 Working with Telephony Utilities 1.2 Using SMS 1.3 Making and Receiving Phone Calls 2
  3. DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Working with Telephony Utilities Ø If your application uses telephony features, make sure you set the 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-elem 3
  4. DONG NAI UNIVERSITY OF TECHNOLOGY 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 information about the phone service itself, such as the phone number of the handset. Read more details: http:// developer.android.com/reference/android/telephony/Telephon 4
  5. DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Working with Telephony Utilities Ø Cont… 5
  6. DONG NAI UNIVERSITY OF TECHNOLOGY 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. 6
  7. DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Working with Telephony Utilities Ø Cont… 7
  8. DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Working with Telephony Utilities Ø Cont… 8
  9. DONG NAI UNIVERSITY OF TECHNOLOGY 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. 9
  10. DONG NAI UNIVERSITY OF TECHNOLOGY 1.1 Working with Telephony Utilities Ø Cont… 10
  11. DONG NAI UNIVERSITY OF TECHNOLOGY 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() 11
  12. DONG NAI UNIVERSITY OF TECHNOLOGY 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. 12
  13. DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Using SMS Ø Gaining Permission to Send and Receive SMS Messages SMS functionality requires two different permissions, depending on whether the application sends or receives messages 13
  14. DONG NAI UNIVERSITY OF TECHNOLOGY 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. 14
  15. DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Using SMS Ø Cont.. 15
  16. DONG NAI UNIVERSITY OF TECHNOLOGY 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) q Two ways to register a BroadcastReceiver ü In coding : using the registerReceiver method ü In Manifest XML: using the receiver tag 16
  17. DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Using SMS Ø By coding pdus 17
  18. DONG NAI UNIVERSITY OF TECHNOLOGY 1.2 Using SMS Ø By Manifest 18
  19. DONG NAI UNIVERSITY OF TECHNOLOGY 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); // Process cursor here (using available column names in SMS table) 19
  20. DONG NAI UNIVERSITY OF TECHNOLOGY 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 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2