Telephony API
   Ramin Orujov
    22.04.2012
Agenda
•   API overview
•   Working with SMS
•   Working with phone calls
•   Working with MMS
API Overview
• http://developer.android.com/reference/andr
  oid/telephony/package-summary.html
SMS
Permissions:
• android.permission.SEND_SMS
• android.permission.RECEIVE_SMS
Main classes:
• SmsManager
• SmsMessage
SMS
How to send sms
• Get SmsManager instance
SmsManager m = SmsManager.getDefault();
• Send text sms
void sendTextMessage (String destinationAddre
  ss, String scAddress, String text, PendingIntent
   sentIntent, PendingIntentdeliveryIntent)
SMS
How to read incoming sms
Extends BroadcastReceiver and listen for action
android.provider.Telephony.SMS_RECEIVED

How to get sent and delivery report
PendingIntent for both actions
SMS
• API docs
http://developer.android.com/reference/androi
  d/telephony/SmsManager.html
Phone call
• Call number
• Detect incoming and outgoing calls
• Listen phone state changes
Phone call
How to call number
Intent intent = new Intent(Intent.ACTION_CALL,
  Uri.parse("tel:502310109"));
  startActivity(intent);

Permission:
• android.permission.CALL_PHONE
Phone call
How to detect incoming and outgoing calls
• Extend BroadcastReceiver and listen for action
android.intent.action.PHONE_STATE
android.intent.action.NEW_OUTGOING_CALL
Phone call
• How to get phone state change events
Permissions
• android.permission.READ_PHONE_STATE
• android.permission.ACCESS_COARSE_LOCATION
• android.permission.ACCESS_NETWORK_STATE
• android.permission.ACCESS_COARSE_UPDATES
Phone call
• API docs
http://developer.android.com/reference/androi
  d/telephony/TelephonyManager.html
MMS
Uri mmsUri =
   Uri.parse("content://media/external/images/media/1");

  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.putExtra("sms_body", “This is a test mms  ");
  intent.putExtra(Intent.EXTRA_STREAM, mmsUri);
  intent.setType("image/png");
  startActivity(intent);
References
Pro Android 4 book
http://www.amazon.com/Pro-Android-4-Professional-
Apress/dp/1430239301/

http://mobiforge.com/developing/story/sms-messaging-android

http://developer.android.com/reference/android/telephony/Tele
phonyManager.html

http://www.tested.com/news/how-to/articles/557-how-to-
measure-cell-signal-strength-on-android-phones/
Questions?
Contact me

http://raminorucov.wordpress.com
http://www.facebook.com/ramin.orucov
http://www.linkedin.com/in/raminorujov
http://twitter.com/RaminOrujov

Telephony API