Nima
Nima

Reputation: 429

Make Phone Call Directly Xamarin.Forms

is there anyway to make a phone call directly without opening the dialler in xamarin.forms?

 if (device.PhoneService != null) {
    Device.OpenUri(new Uri("tel:123123123"));
 }

Upvotes: 15

Views: 11383

Answers (3)

Yksh
Yksh

Reputation: 3306

When we code to start a voice call, we must be aware of DependencyService in Xamarin.Forms.

DependencyService in Xamarin.Forms provides access to the native functionality and some platform-specific implementations of the iOS, Android and Windows Phone SDKs from your PCL or Shared Project.

To start a voice call there are some platform-specific implementations and permissions.

  1. The following is the procedure to implement the voice call in Xamarin.Forms. Let's create a ContentPage with an entry and a button as HomePage.cs.

enter image description here
(source: netdna-cdn.com)

  1. Create an interface IPhoneCall.cs in the shared code that shows the functionality that we intend to implement.

enter image description here
(source: netdna-cdn.com)

  1. The Interface must be implemented in each platform-specific application project.

Android implementation: Before implementing the interface in Android don't forget to set some permissions in AndroidManifest.xml. These permissions are necessary for invoking a voice call in Android.

enter image description here
(source: netdna-cdn.com)

After setting the permissions we must implement the interface using a small class PhoneCall_Droid.cs.

enter image description here
(source: netdna-cdn.com)

Refer Sample for iOS & Windows Implementation.

  1. We had completed implementing the interface and registering each specific platform. Now we can write DependencyService to get an instance of the interfaces.

enter image description here
(source: netdna-cdn.com)


Sample : http://www.c-sharpcorner.com/UploadFile/e4bad6/code-to-start-call-in-xamarin-forms


Upvotes: 6

SmartyP
SmartyP

Reputation: 1359

Devices always show the dialer when you make a phone call, so that the user can hang up, switch to a bluetooth device, mute, etc. - that is how launching a dialer works on mobile. On iOS after the call ends the user will still be in your app, and this question below talks about how to bring the user back to your app on Android after the call ends:

How to make a phone call in android and come back to my activity when the call is done?

Upvotes: 0

JamesMontemagno
JamesMontemagno

Reputation: 3792

Simply use the messaging plugin to do this from shared code. Works great: https://github.com/cjlotz/Xamarin.Plugins

Upvotes: 3

Related Questions