I'm building an app using xamarin android, I'm implementing a feature where I want to answer call programmatically; I have an idea that I need to use Intent
but how? that's what I don't know.
Any one can suggest me?
You can write a broadcast receiver that will manage your incoming call:
[BroadcastReceiver]
[IntentFilter (new [] {"android.intent.action.PHONE_STATE"})]
public class IncomingPhoneCallDetector : BroadcastReceiver
{
public override void OnReceive(Context context, 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))
{
Toast.MakeText (context, "Incoming call from " + telephone + ".", ToastLength.Short).Show ();
}
else
{
Toast.MakeText (context, "Incoming call from unknown number.", ToastLength.Short).Show ();
}
Intent buttonDown = new Intent(Intent.ActionMediaButton);
buttonDown.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Up, Keycode.Headsethook));
context.SendOrderedBroadcast (buttonDown, "android.permission.CALL_PRIVILEGED");
}
else if (state == TelephonyManager.ExtraStateOffhook)
{
Toast.MakeText(context, "Incoming call answered.", ToastLength.Short).Show();
}
else if (state == TelephonyManager.ExtraStateIdle)
{
Toast.MakeText(context, "Incoming call ended.", ToastLength.Short).Show();
}
}
}
}
Cheers!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.