Chapter 6
Android Telephony
Telephone Manager
[Link] class provides
information about the telephony services such as
subscriber id, sim serial number, phone network type etc.
//Get the instance of TelephonyManager
TelephonyManager tm=(TelephonyManager)getSystemService(Context.T
ELEPHONY_SERVICE);
//Calling the methods of TelephonyManager the returns the information
String IMEINumber=tm. getIMEINumber();
String subscriberID=[Link]();
String phoneID=tm.getLine1Number();
String SIMSerialNumber=[Link]();
String networkCountryISO=[Link]();
String SIMCountryISO=[Link]();
String softwareVersion=[Link]();
String voiceMailNumber=[Link]();
Give READ_PHONE_STATE permission in android manifest file
<uses-
permission android:name="[Link].READ_PHONE_STATE"/>
Make a phone call
making a phone call from our android
applications is done easily by invoking built-in
phone calls app using Intents action
(ACTION_CALL).
Intent callIntent
= new Intent(Intent.ACTION_CALL);
[Link]([Link]("[Link] + [Link]
ext().toString()));
startActivity(callIntent);
we need to add a CALL_PHONE permission in
our android manifest.
<uses-
permission android:name="[Link].CALL_P
HONE" />
Sending SMS
we can send SMS from our android application in
two ways either by
using SMSManager api or
SmsManager smgr = [Link]();
[Link](MobileNumber,null,Message,null,null);
Intents ACTION_VIEW action
Intent sInt = new Intent(Intent.ACTION_VIEW);
[Link]("address", new String[]
{[Link]().toString()});
[Link]("sms_body",[Link]().toString());
[Link]("[Link]-dir/mms-sms");
Make sure to allow SEND_SMS permission android
manifest file
<uses-
permission android:name="[Link].SEND_SMS
" />
Sending Email
we can easily send an email from our android application using
existing email clients such as GMAIL, Outlook, etc
The Intent object in android with proper action (ACTION_SEND) and
data will help us to launch the available email clients to send an
email in our application
Intent it = new Intent(Intent.ACTION_SEND);
[Link](Intent.EXTRA_EMAIL, new String[]{"abc@[Link] "});
[Link](Intent.EXTRA_SUBJECT, "test");
[Link](Intent.EXTRA_TEXT, "Hello this is to inform you that….");
[Link]("message/rfc822");
it - Our local implicit intent
ACTION_SEND - It’s an activity action which specifies that we are
sending some data.
putExtra - add extra information to our Intent. Example: recipient,
subject and message
EXTRA_EMAIL - It’s an array of email addresses
EXTRA_SUBJECT - The subject of the email that we want to send
EXTRA_TEXT - The body of the email
setType - set the MIME type of data to be sent.
Example“message/rfc822” and other MIME types are “text/plain” and
“image/jpg”.
We need to add MIME type and Permission in our android manifest
file code like as shown below
<manifest …>
<application
…
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
<action android:name="[Link]"/>
<category android:name="[Link]"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>
</activity>
</application>
</manifest>
action - we use this property to define that the activity can
perform SEND action.
category - we included the DEFAULT category for this activity to be
able to receive implicit intents.
data - the type of data the activity can send.