gpt4 book ai didi

android - 如何以编程方式接听电话 Xamarin |安卓

转载 作者:行者123 更新时间:2023-11-29 14:46:46 25 4
gpt4 key购买 nike

我正在使用 xamarin android 构建一个应用程序,我正在实现一个我想以编程方式接听电话的功能;我有一个想法,我需要使用 Intent 但如何呢?这就是我不知道的。

有人可以推荐我吗?

最佳答案

您可以编写一个广播接收器来管理您的来电:

[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();
}
}
}
}

干杯!

关于android - 如何以编程方式接听电话 Xamarin |安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33300995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com