5

I am developing an cross platform application using Xamarin, for SIP calling. I have incoming and outgoing calls working.

Although, I have a problem with receiving call in when the App is running in the background.

I have tried to bring application to front, when a call is received. The code I have used follows:

In my MainActivity

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

and in my 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);
}

I tried with different ActivityFlags like NewTask, SingleTop, ReorderToFront, ReceiverForeground, FromBackground, BroughtToFront. However, noting will bring my app to the foreground.

What else can I do from here?

I have tried following this Link. Although it didn't help.

Cœur
  • 37,241
  • 25
  • 195
  • 267
askitanna
  • 78
  • 1
  • 1
  • 7

1 Answers1

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

Should launch your App just fine.

Are you sure your BroadcastReceiver is called?

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118