Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"));
 }
like image 396
Nima Avatar asked Nov 23 '15 20:11

Nima


People also ask

How to make Phone call in Xamarin forms?

using Xamarin. Essentials; The Phone Dialer functionality works by calling the Open method with a phone number to open the dialer with. When Open is requested the API will automatically attempt to format the number based on the country code if specified.

How do I open dialer in xamarin?

Essentials Reference, Choose Browse and Search Xamarin. Essentials, select the package and select all the projects (portable, Android, UWP) and install it. Add the Label, Entry and Button controls in Mainpage. Xaml for displaying Title, phone number and call now.

What is xamarin essentials?

Xamarin. Essentials provides a single cross-platform API that works with any iOS, Android, or UWP application that can be accessed from shared code no matter how the user interface is created. See the platform & feature support guide for more information on supported operating systems.

How does xamarin form improve app performance?

Use fast Renderers Fast renderers reduce extensions and rendering the cost of controls on android by flattering the resulting native control hierarchy. It also improves performance by creating fewer objects, which turns results in a less complex visual tree and memory use.


2 Answers

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


like image 59
Yksh Avatar answered Sep 19 '22 14:09

Yksh


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

like image 26
JamesMontemagno Avatar answered Sep 17 '22 14:09

JamesMontemagno