In my Xamarin application, after user clicks some button I want to make a phone call and then return to my app (ideally to the same place in the code).
Something like this:
async Task button_click()
string s = "200-345-6789";
// await Device.OpenUri("tel:" + s); // can't await this
ShowAlert("The number " + s + " was called");
After messing with this for some more hours, I found the solution - so I thought I'd post it for others to benefit.
What I did is simulation of something similar to Android's
AppDelegate class I define an event which is fired from its
Now, inside my function I subscribe to this event passing to the delegate a
TaskCompletionSource which I define. Then I call
Device.OpenUri("tel:" + phoneNum). The phone call is made, and after it ends the user is returned to my app,
AppDelegate.OnActivated fires my event, my delegate is called and I can mark my task as completed by calling
SetResult. This makes possible to
await this function.