Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public class InCallLogger extends BroadcastReceiver {
  2.  
  3. Context ctx;
  4. String number;
  5.  
  6. @Override
  7. public void onReceive(final Context context, Intent intent) {
  8. ctx = context;
  9.  
  10. Bundle extras = intent.getExtras();
  11. if (extras == null)
  12. return;
  13. String state = extras.getString(TelephonyManager.EXTRA_STATE);
  14. if (state == null)
  15. return;
  16. gps = new Gpsadd(context);
  17.  
  18. // ringing
  19. if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
  20.  
  21. timeStarted = System.currentTimeMillis();
  22.  
  23. number = extras
  24. .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
  25. number = number.toString().replaceAll("\+", "");
  26. // System.out.println("From mesages::" + message);
  27. TelephonyManager tm = (TelephonyManager) context
  28. .getSystemService(Context.TELEPHONY_SERVICE);
  29. simNumber = tm.getLine1Number();
  30. isRoaming = tm.isNetworkRoaming();
  31. System.out.println("incoming call broadcast ringing");
  32.  
  33. return;
  34. }
  35.  
  36. // answered
  37. if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)
  38. && timeStarted != -1L) {
  39.  
  40.  
  41. return;
  42. }
  43.  
  44. // ended
  45. if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)
  46. && timeStarted != -1L) {
  47.  
  48.  
  49.  
  50. return;
  51.  
  52. }
  53. }
  54.  
  55. <uses-permission android:name="android.permission.CALL_PHONE" />
  56. <receiver android:name="incoming.InCallLogger" >
  57. <intent-filter>
  58. <action android:name="android.intent.action.PHONE_STATE" />
  59. </intent-filter>
  60. </receiver>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement