Launching The Phone Dialer Activity Using Xamarin Android Application

Overview

Xamarin is a development platform, which allows us to code native, cross-platform iOS, Android and Windows Phone apps in C#. This tutorial focuses on Xamarin Android Intent Action to launch the phone dialer.

Requirements

  • Visual Studio RC 2017
  • Xamarin Studio Packages Should be installed

The steps are given below, which should be followed.

Please follow my steps to create launching the phone dialer and use this tutorial effectively. An intent is an abstract description of an operation to be performed.

Step 1

Launch Visual Studio RC 2017 and go to File-> New-> Project.

 

Step 2

Now, we need to select the Android template from the List, name the Application, press to create the Project and select where to save the project.

 

Step 3

We go to our new project, which has been created and then we need to navigate to Designer Page. To open the designer page, you need to open Solution Explorer ViewàSolution Explorer.

 

Step 4

To open Designer Page, we need to select the following-> Solution ExploreràResourcesàLayoutàMain.Xaml.

 

Step 5

Add the code given below in Main.Xaml Source page. This main.xaml file is our designer page and here, our Intent Action will be present. This is the Designer Page for our Application.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.    android:orientation="vertical"  
  4.    android:layout_width="match_parent"  
  5.    android:layout_height="match_parent">  
  6. <Button  
  7.    android:id="@+id/MyButton"  
  8.    android:layout_width="match_parent"  
  9.    android:layout_height="wrap_content"  
  10.    android:text="99510256" />  
  11. </LinearLayout>  

Step 6

Add the code given below in MainActivity.cs. This main acitivity is the one, which plays most important role and this makes our app to work correctly and customizing the buttons with the background activity.

  1. using System;  
  2. using Android.App;  
  3. using Android.Content;  
  4. using Android.Runtime;  
  5. using Android.Views;  
  6. using Android.Widget;  
  7. using Android.OS;  
  8. namespace IntentAction {  
  9.     [Activity(Label = "IntentAction", MainLauncher = true, Icon = "@drawable/icon")]  
  10.     public class MainActivity: Activity {  
  11.         protected override void OnCreate(Bundle bundle) {  
  12.             base.OnCreate(bundle);  
  13.             // Set our view from the "main" layout resource  
  14.             SetContentView(Resource.Layout.Main);  
  15.             // Get our button from the layout resource,  
  16.             // and attach an event to it  
  17.             Button button = FindViewById < Button > (Resource.Id.MyButton);  
  18.             button.Click += delegate {  
  19.                 var uri = Android.Net.Uri.Parse("tel:4567900");  
  20.                 var intent = new Intent(Intent.ActionDial, uri);  
  21.                 StartActivity(intent);  
  22.             };  
  23.         }  
  24.     }  
  25. }   

Final step

Now, run the app, using Visual Studio Android Emulator and here, we go to our app, which gets executed.

 

Output

Launch the phone dialer.

 

Conclusion

Thank you for reading. Please make use of this blog. If you have any doubt, query, comment below. If you like it, follow me for more updates about Xamarin Android app development.

Ebook Download
View all
Learn
View all