Android telephony api

3,313 views

Published on

Published in: Technology, Business
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
3,313
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
227
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Android telephony api

  1. 1. Mr. Pritesh N. Patel Assistant Professor MCA ISTAR. V. V. Nagar
  2. 2.  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.
  3. 3.  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.
  4. 4.  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“/>
  5. 5.  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);
  6. 6. PhoneCallListener phoneListener = new PhoneCallListener(); TelephonyManager telephonyManager = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SER VICE); telephonyManager.listen(phoneListener,Phon eStateListener.LISTEN_CALL_STATE);
  7. 7. 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; } } } }
  8. 8. String formatNumber = PhoneNumberUtils.formatNumber(“9726344355”); Output: 972-634-4355
  9. 9. 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>

×