Making phone calls
Our app may need to initiate a phone call from within the app without the user having to leave the current context.
How to do it...
To initiate a call directly from within our app, we use an Intent
instance:
We first need to ensure that the device has telephony features. There are two ways to do this; one way is to use attributes:
[assembly: UsesFeature( Android.Content.PM.PackageManager.FeatureTelephony)]
Alternatively, we can check for the telephony feature using the
HasSystemFeature()
method at runtime:var hasTelephony = PackageManager.HasSystemFeature( Android.Content.PM.PackageManager.FeatureTelephony); if (hasTelephony) { // do something }
If we are running on a device with telephony features, we still need to request permissions to start phone calls:
[assembly: UsesPermission(Manifest.Permission.CallPhone)]
Finally, we can make the phone call using the
ActionCall
action intent:var number = "0123456789"; var intent = new Intent(Intent.ActionCall); intent.SetData(Uri...