Android Telephony Manager and SMS

8

Click here to load reader

Transcript of Android Telephony Manager and SMS

Page 1: Android Telephony Manager and SMS

Android  Telephony  and  Messaging  

Jussi  Pohjolainen  

Page 2: Android Telephony Manager and SMS

Overview  

•  Telephone  API  is  used  monitor  phone  informa=on  – States  of  phone,  connec=on  

•  Available  in  package  android.telephony  •  Classes  like:  SmsManager,  TelephonyManager  

Page 3: Android Telephony Manager and SMS

TelephonyManager  

•  Class  to  determine  telephony  services  and  states  –  IDLE,  RINGING,  DATA_CONNECTED…  

•  App  can  register  to  receive  no=fica=ons  of  state  changes  

•  Some  telephony  informa=on  needs  permissions  to  be  set  in  the  manifest:  –   <uses-permission android:name="android.permission.READ_PHONE_STATE” />

Page 4: Android Telephony Manager and SMS

Example  

LISTEN_DATA_ACTIVITY  LISTEN_SIGNAL_STRENGTHS  

…  

Page 5: Android Telephony Manager and SMS

SmsManager  

•  Manages  SMS  opera=ons  such  as  sending  data,  text,  and  pdu  SMS  messages.    

•  Get  this  object  by  calling  the  sta=c  method  SmsManager.getDefault().  

•  Add  permission:  android.permission.SEND_SMS  

Page 6: Android Telephony Manager and SMS

Sending  SMS  

 (SmsManager.getDefault()).sendTextMessage("+3585012345", null, “message”, null, null);

Page 7: Android Telephony Manager and SMS

Receiving  SMS  <receiver  android:name=".SmsReceiver">            <intent-­‐filter>                    <ac=on  android:name=                                          "android.provider.Telephony.SMS_RECEIVED"  />            </intent-­‐filter>    </receiver>  

Page 8: Android Telephony Manager and SMS

Receiving  SMS