15

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"));
 }
Nima
  • 429
  • 1
  • 5
  • 8
  • Have you looked at XLabs? There is a PhoneCallTask which may do what you want see here: https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Platform/XLabs.Platform.WP8/Services/PhoneService.cs – TResponse Nov 23 '15 at 21:02
  • @loanburger it's exactly what I used. but it shows Dialler. – Nima Nov 23 '15 at 21:58
  • You can pass the dialer on Android by using an activity with `Intent.ACTION_CALL` if you request the `android.permission.CALL_PHONE` manifest permission, but iOS does not allow something like that, you are going to get the dialer. – SushiHangover Nov 23 '15 at 22:17
  • how should I use INTENT in Xamarin.Forms?? – Nima Nov 23 '15 at 22:28

3 Answers3

6

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


Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Yksh
  • 3,276
  • 10
  • 56
  • 101
3

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

JamesMontemagno
  • 3,782
  • 1
  • 12
  • 13
  • thanks but it doesn't call directly! it opens dialler, I don't know why! – Nima Nov 25 '15 at 18:27
  • var dialIntent = new Intent(Intent.ActionDial, telUri); https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Lotz.Xam.Messaging.Android/PhoneCallTask.cs#L31 – Nima Nov 25 '15 at 20:36
0

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?

Community
  • 1
  • 1
SmartyP
  • 1,329
  • 1
  • 8
  • 13