Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. [BroadcastReceiver()]
  2. [IntentFilter(new[]{TelephonyManager.ActionPhoneStateChanged
  3. /* "android.intent.action.PHONE_STATE" */ })]
  4. public class IncomingCallReceiver : BroadcastReceiver
  5. {
  6. public override void OnReceive(Context context, Intent intent)
  7. {
  8. // בדיקת אם יש מידע ב-intent
  9. if (intent.Extras != null)
  10. {
  11. // קריאת מצב השיחה
  12. string state = intent.GetStringExtra(TelephonyManager.ExtraState);
  13.  
  14. // בדיקת מצב השיחה
  15. if (state == TelephonyManager.ExtraStateRinging)
  16. {
  17. // קריאת מס' הטלפון המתקשר
  18. string telephone = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);
  19.  
  20. if (string.IsNullOrEmpty(telephone))
  21. telephone = string.Empty;
  22.  
  23. Intent intent2 = new Intent(context, typeof(MediaService));
  24. intent2.PutExtra("ACTION", "inComingCall");
  25. context.StartService(intent2);
  26. Toast.MakeText(context, "Calling number: " + telephone, ToastLength.Short).Show();
  27. }
  28. else if (state == TelephonyManager.ExtraStateOffhook)
  29. {
  30. // מענה לשיחה נכנסת
  31. Toast.MakeText(context, "Now talking", ToastLength.Short).Show();
  32. }
  33. else if (state == TelephonyManager.ExtraStateIdle)
  34. {
  35. // תגובה לסיום השיחה
  36. Toast.MakeText(context, "Call eneded", ToastLength.Short).Show();
  37. Intent intent2 = new Intent(context, typeof(MediaService));
  38. intent2.PutExtra("ACTION", "callEnded");
  39. context.StartService(intent2);
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement