Guest User

Untitled

a guest
Jun 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
  2. Log.v("ranjith", "Entered in callstatelistener");
  3.  
  4. <!-- declare the permission -->
  5. <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  6.  
  7. <application
  8. android:allowBackup="true"
  9. android:icon="@drawable/ic_launcher"
  10. android:label="@string/app_name"
  11. android:theme="@style/AppTheme" >
  12.  
  13. <!-- Register your Broadcast receiver -->
  14. <receiver android:name=".CallReceiver" android:enabled="true">
  15. <intent-filter>
  16. <action android:name="android.intent.action.PHONE_STATE" />
  17. </intent-filter>
  18. </receiver>
  19.  
  20. </application>
  21.  
  22. public class CallReceiver extends BroadcastReceiver {
  23.  
  24. static boolean isRinging = false;
  25. static boolean isCallReceived = false;
  26.  
  27. @Override
  28. public void onReceive(Context context, Intent intent) {
  29. // TODO Auto-generated method stub
  30.  
  31. // Get the current Phone State
  32. String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
  33.  
  34. if(phoneState == null)
  35. return;
  36.  
  37. // If phone is "Rininging"
  38. if(phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING))
  39. {
  40. isRinging = true;
  41. }
  42.  
  43. // If an incoming call is received
  44. if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
  45. {
  46. isCallReceived = true;
  47. }
  48.  
  49. // if phone is idle
  50. if (phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)){
  51. // detect call not received
  52. if(isRinging == true && isCallReceived == false){
  53. Toast.makeText(context, "Call was not received!", Toast.LENGTH_LONG).show();
  54. }
  55. }
  56. }
Add Comment
Please, Sign In to add comment