Pouvez-vous m’aider à comprendre comment détecter si l’appel sortant est pris en charge ou non (je dois enregistrer un appel en commençant à partir de la réponse jusqu’à la fin)? Je peux le détecter pour les appels entrants mais pas pour les appels sortants. Alors s’il vous plaît aider.
Utilisez TelephonyManager.ActionPhoneStateChanged
pour surveiller l’état de TelephonyManager
lors de la réception de TelephonyManager.ExtraStateIdle
vous savez que la radio du téléphone est maintenant inactive (aucun appel en cours).
[BroadcastReceiver(Name = "com.sushhangover.OutgoingCallBroadcastReceiver")] [IntentFilter(new[] { Intent.ActionNewOutgoingCall, TelephonyManager.ActionPhoneStateChanged })] public class OutgoingCallBroadcastReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { switch (intent.Action) { case Intent.ActionNewOutgoingCall: var outboundPhoneNumber = intent.GetSsortingngExtra(Intent.ExtraPhoneNumber); Toast.MakeText(context, $"Started: Outgoing Call to {outboundPhoneNumber}", ToastLength.Long).Show(); break; case TelephonyManager.ActionPhoneStateChanged: var state = intent.GetSsortingngExtra(TelephonyManager.ExtraState); if (state == TelephonyManager.ExtraStateIdle) Toast.MakeText(context, "Phone Idle (call ended)", ToastLength.Long).Show(); else if (state == TelephonyManager.ExtraStateOffhook) Toast.MakeText(context, "Phone Off Hook", ToastLength.Long).Show(); else if (state == TelephonyManager.ExtraStateRinging) Toast.MakeText(context, "Phone Ringing", ToastLength.Long).Show(); else if (state == TelephonyManager.ExtraIncomingNumber) { var incomingPhoneNumber = intent.GetSsortingngExtra(TelephonyManager.ExtraIncomingNumber); Toast.MakeText(context, $"Incoming Number: {incomingPhoneNumber}", ToastLength.Long).Show(); } break; default: break; } } }
Remarque: veillez à append des permissions à ReadPhoneState
et ProcessOutgoingCalls
pour que cet exemple fonctionne.