Introduction
In this blog, we will dial a number from Android and iOS app. This is a very useful and general functionality of an app.
In this blog, we will dial a number from Android and iOS app. This is a very useful and general functionality of an app.
Interface
The interface will have a common method, which will be used by an Android and iOS app to dial a number. We will place this file in our PCL (Portable Class Library) project.
The interface will have a common method, which will be used by an Android and iOS app to dial a number. We will place this file in our PCL (Portable Class Library) project.
- namespace Sample.Mobile.Services.Common
- {
- public interface IDialer
- {
- bool Dial(string number);
- }
- }
Android Dialer Implementation
We will place this file in Android project and implement the interface function.
We will place this file in Android project and implement the interface function.
- using System.Linq;
- using Android.Content;
- using Android.Telephony;
- using Xamarin.Forms;
- using Sample.Mobile.Droid.Helper;
- using Sample.Mobile.Services.Common;
- [assembly: Xamarin.Forms.Dependency(typeof(PhoneDialer))]
- namespace Sample.Mobile.Droid.Helper
- {
- public class PhoneDialer : IDialer
- {
- public bool Dial(string number)
- {
- var context = Forms.Context;
- if (context == null)
- return false;
- var intent = new Intent(Intent.ActionDial);
- intent.SetData(Android.Net.Uri.Parse("tel:" + number));
- if (IsIntentAvailable(context, intent))
- {
- context.StartActivity(intent);
- return true;
- }
- return false;
- }
- private static bool IsIntentAvailable(Context context, Intent intent)
- {
- var packageManager = context.PackageManager;
- var list = packageManager.QueryIntentServices(intent, 0)
- .Union(packageManager.QueryIntentActivities(intent, 0));
- if (list.Any())
- return true;
- TelephonyManager mgr = TelephonyManager.FromContext(context);
- return mgr.PhoneType != PhoneType.None;
- }
- }
- }

Former memberPosted Dec 27, 2017, 6:26 AM
Thank You, Mehul. The above mentioned are informative and so useful. I’m trying to find same Xamarin iOS blogs and I found this post and perfect, it is like a package.