Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BroadcastReceiver()]
- [IntentFilter(new[]{TelephonyManager.ActionPhoneStateChanged
- /* "android.intent.action.PHONE_STATE" */ })]
- public class IncomingCallReceiver : BroadcastReceiver
- {
- public override void OnReceive(Context context, Intent intent)
- {
- // בדיקת אם יש מידע ב-intent
- if (intent.Extras != null)
- {
- // קריאת מצב השיחה
- string state = intent.GetStringExtra(TelephonyManager.ExtraState);
- // בדיקת מצב השיחה
- if (state == TelephonyManager.ExtraStateRinging)
- {
- // קריאת מס' הטלפון המתקשר
- string telephone = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);
- if (string.IsNullOrEmpty(telephone))
- telephone = string.Empty;
- Intent intent2 = new Intent(context, typeof(MediaService));
- intent2.PutExtra("ACTION", "inComingCall");
- context.StartService(intent2);
- Toast.MakeText(context, "Calling number: " + telephone, ToastLength.Short).Show();
- }
- else if (state == TelephonyManager.ExtraStateOffhook)
- {
- // מענה לשיחה נכנסת
- Toast.MakeText(context, "Now talking", ToastLength.Short).Show();
- }
- else if (state == TelephonyManager.ExtraStateIdle)
- {
- // תגובה לסיום השיחה
- Toast.MakeText(context, "Call eneded", ToastLength.Short).Show();
- Intent intent2 = new Intent(context, typeof(MediaService));
- intent2.PutExtra("ACTION", "callEnded");
- context.StartService(intent2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement