• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android telephony api

Android telephony api






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Android telephony api Android telephony api Presentation Transcript

    • Mr. Pritesh N. Patel Assistant Professor MCA ISTAR. V. V. Nagar
    •  An Android SDK provides number of useful utilities for application to integrate phone feature available on the device. 1. Application may need to know the state of phone call and behave accordingly. 2. Application may need to place a call or want to send a text SMS.
    •  It Provides access to information about the telephony services on the device.  Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information.  Applications can also register a listener to receive notification of telephony state changes.  The telephony API is used to among other things monitor phone information including the current states of the phone, connections, network etc.  Access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file.
    •  The TelephonyManager object within the android.telephony package is used to handle phone state.  You do not instantiate this class directly; instead, you retrieve a reference to an instance through Context.getSystemService(Context.TELEPHONY_SERVICE) For e.g. TelephonyManager tMger; tMger =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); Permission for Phone Service <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS“/>
    •  Following code snippet is used to call a phone. Write a code on Button click and get phone number from EditText view. Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:9726344355")); startActivity(callIntent);
    • PhoneCallListener phoneListener = new PhoneCallListener(); TelephonyManager telephonyManager = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SER VICE); telephonyManager.listen(phoneListener,Phon eStateListener.LISTEN_CALL_STATE);
    • private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; String LOG_TAG = "LOGGING 123"; @Override public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { Log (LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { Log.i(LOG_TAG, "IDLE"); if (isPhoneCalling) { Log.i(LOG_TAG, "restart app"); Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage( getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); isPhoneCalling = false; } } } }
    • String formatNumber = PhoneNumberUtils.formatNumber(“9726344355”); Output: 972-634-4355
    • private void sendSms(String one,String two) { Intent i=new Intent(this,MainActivity.class); PendingIntent pi=PendingIntent.getActivity(this, 0, i,0); SmsManager sms=SmsManager.getDefault(); sms.sendTextMessage(tNo, null, msg, pi,null); } Permission for SMS Service <uses-permission android:name="android.permission.SEND_SMS"> </uses-permission> <uses-permission android:name="android.permission.RECEIVE_SMS"> </uses-permission>