小编ask*_*nna的帖子

通过BroadcastReciver接收来电时,将应用程序从后台运行到前台

我正在使用Xamarin开发一个用于SIP呼叫的跨平台应用程序.我有传入和传出呼叫工作.

虽然,当应用程序在后台运行时,我遇到接收呼叫的问题.

当收到电话时,我试图将应用程序带到前面.我使用的代码如下:

在我的MainActivity中

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

在我的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);
}
Run Code Online (Sandbox Code Playgroud)

我试着用不同的ActivityFlagsNewTask, …

xamarin.android xamarin.forms

5
推荐指数
1
解决办法
1142
查看次数

标签 统计

xamarin.android ×1

xamarin.forms ×1