gpt4 book ai didi

xamarin.android - 通过 BroadcastReceiver 接收来电时将应用程序从后台带到前台

转载 作者:行者123 更新时间:2023-12-04 21:39:07 26 4
gpt4 key购买 nike

我正在使用 Xamarin 开发跨平台应用程序,用于 SIP 调用。我有来电和去电工作。

虽然,当应用程序在后台运行时,我在接听电话时遇到了问题。

当接到电话时,我试图将应用程序放在前面。我使用的代码如下:

在我的主要事件中

private void registerReceiver()
{
IncomingCallReceiver callReceiver = new IncomingCallReceiver();
IntentFilter sipIntentFilter = new IntentFilter();
sipIntentFilter.AddAction("com.NelsonApp.INCOMING_CALL");
this.RegisterReceiver(callReceiver, sipIntentFilter);
}

并在我的 BroadcastReceiver 中

public override void OnReceive(Context context, Intent intent)
{
DialerCallListener listener = new DialerCallListener();
SIPRegistration.call = SIPRegistration.sipManager.TakeAudioCall(intent, listener);

string str = SIPRegistration.call.PeerProfile.UriString;
char [] strArray = {':','@'};
var value = str.Split(strArray)[1];

Intent newIntent = new Intent(context, typeof(MainActivity));

newIntent.AddFlags(ActivityFlags.FromBackground);
newIntent.AddCategory(Intent.CategoryLauncher);
context.StartActivity(newIntent);

PlaySound myActivity = new PlaySound();
myActivity.PlayRingtone(context);

MainActivity.isIncomingCall = true;
MessagingCenter.Send(string.Empty, "IncomingCall", value);
}

我尝试了不同的 ActivityFlags喜欢 NewTask , SingleTop , ReorderToFront , ReceiverForeground , FromBackground , BroughtToFront .但是,注意会将我的应用程序带到前台。

我还能从这里做什么?

我试过关注这个 Link .虽然它没有帮助。

最佳答案

var intent = new Intent(context, typeof (MainActivity));
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);

应该可以正常启动您的应用程序。

你确定你的 BroadcastReceiver叫做?

关于xamarin.android - 通过 BroadcastReceiver 接收来电时将应用程序从后台带到前台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31385176/

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