Android	
  Telephony	
  and	
  
     Messaging	
  
       Jussi	
  Pohjolainen	
  
Overview	
  
•  Telephone	
  API	
  is	
  used	
  monitor	
  phone	
  
   informa=on	
  
   –  States	
  of	
  phone,	
  connec=on	
  
•  Available	
  in	
  package	
  android.telephony	
  
•  Classes	
  like:	
  SmsManager,	
  TelephonyManager	
  
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” />
Example	
  


                 LISTEN_DATA_ACTIVITY	
  
              LISTEN_SIGNAL_STRENGTHS	
  
                          …	
  
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	
  
Sending	
  SMS	
  
	
  
(SmsManager.getDefault()).sendTextMessa
ge("+3585012345", null, “message”,
null, null);
Receiving	
  SMS	
  
<receiver	
  android:name=".SmsReceiver">	
  	
  
	
  	
  	
  	
  <intent-­‐filter>	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  <ac=on	
  android:name=	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "android.provider.Telephony.SMS_RECEIVED"	
  />	
  	
  
	
  	
  	
  	
  </intent-­‐filter>	
  	
  
</receiver>	
  
Receiving	
  SMS	
  

Android Telephony Manager and SMS

  • 1.
    Android  Telephony  and   Messaging   Jussi  Pohjolainen  
  • 2.
    Overview   •  Telephone  API  is  used  monitor  phone   informa=on   –  States  of  phone,  connec=on   •  Available  in  package  android.telephony   •  Classes  like:  SmsManager,  TelephonyManager  
  • 3.
    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” />
  • 4.
    Example   LISTEN_DATA_ACTIVITY   LISTEN_SIGNAL_STRENGTHS   …  
  • 5.
    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  
  • 6.
    Sending  SMS     (SmsManager.getDefault()).sendTextMessa ge("+3585012345", null, “message”, null, null);
  • 7.
    Receiving  SMS   <receiver  android:name=".SmsReceiver">            <intent-­‐filter>                    <ac=on  android:name=                                          "android.provider.Telephony.SMS_RECEIVED"  />            </intent-­‐filter>     </receiver>  
  • 8.