Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Telephony Services
1
Agenda
3
Introduction
LocationManager.GPS_PROVIDER
LocationManager.NETWORK_PROVIDER
LocationManager.PASSIVE_PROVIDER
LBS (Contd.,)
• mapView.setStreetView(true);
• mapView.setTraffic(true);
• mapView.setBuiltInZoomControls(true);
Default View
Using the Map Controller
3
Working with Telephony Manager
• The telephony APIs also include the telephony
manager(android.telephony.TelephonyManager), which
you can use to obtain information about the telephony
services on the device, get subscriber information, and
register for telephony state changes.
• A common telephony use case requires that an
application execute business logic upon incoming phone
calls.
• For example, a music player might pause itself for an
incoming call, and resume when the call has been
completed.
• <uses-permission
android:name="android.permission.READ_PHONE_STATE"/>
Working with Telephony Manager
(Contd.,)
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TelephonyManager teleMgr =
(TelephonyManager)getSystemService(Context.TELEPHONY_SE
RVICE);
teleMgr.listen(new MyPhoneStateListener(),
PhoneStateListener.LISTEN_CALL_STATE);
}
Working with Telephony Manager
(contd.,)
class MyPhoneStateListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state)
{
case TelephonyManager.CALL_STATE_IDLE:
Log.d(TAG, "call state idle...incoming number is["+ incomingNumber+"]");break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "call state ringing...incoming number is["+ incomingNumber+"]");break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d(TAG, "call state Offhook...incoming number is["+ incomingNumber+"]");break;
default:
Log.d(TAG, "call state ["+state+"]incoming number is["+ incomingNumber+"]");break;
}
}
}
SMS
58
SMS
• In many circumstances you may find it easier to pass on
the responsibility for sending SMS messages to another
application, rather than implementing a full SMS client
within your app.
• To do so, call startActivity using an Intent with the
Intent.ACTION_SENDTO action.
• Specify a target
– number using sms: schema notation as the Intent data.
– Include the message you want to send within the Intent
payload using an sms_body extra
Sending SMS Messages Manually
• SMS messaging in Android is handled by the
SmsManager.
• Get a reference to the SMS Manager using-
SmsManager smsManager =
SmsManager.getDefault();
• To send SMS messages, your applications must specify
the SEND_SMS uses-permission.
• To request this permission, add it to the manifest as
shown below:
<uses-permission
android:name="android.permission.SEND_SMS"/>
Sending SMS Messages Manually
(Contd.,)
• To send a text message, use sendTextMessage
from the SMS Manager, passing in the address
(phone number) of your recipient and the text
message you want to send
String sendTo = "5551234";
String myMessage = "Android supports programmatic SMS
messaging!";
smsManager.sendTextMessage(sendTo, null, myMessage, null, null);
SMSC
SMSCtotouse use
(Null
(Null= =use
usedefault)
default) Intents to track the transmission
Intents to track
and successful the transmission
delivery
and successful delivery
Tracking and Confirming SMS
Message Delivery
• To track the transmission and delivery success of your outgoing
SMS messages, implement and register Broadcast Receivers that
listen for the actions you specify when creating the Pending Intents
you pass in to the sendTextMessage method.
• The first Pending Intent parameter, sentIntent, is fired when the
message either is successfully sent or fails to send. The result code
for the Broadcast Receiver that receives this Intent will be one of the
following:
– Activity.RESULT_OK To indicate a successful transmission
– SmsManager.RESULT_ERROR_GENERIC_FAILURE To
indicate a nonspecific failure
– SmsManager.RESULT_ERROR_RADIO_OFF When the phone
radio is turned off
– SmsManager.RESULT_ERROR_NULL_PDU To indicate a
PDU (protocol description unit) failure
• The second Pending Intent parameter, deliveryIntent, is fired only
after the destination recipient receives your SMS message.
Thank-You
58