Download Code

Xamarin Send SMS Call Android

Today you will learn how to send an sms/call using xamarin send sms call android application.

You must have some knowledge of Intent.

First i’ll give some information about classes(SMS Manager,Intent).

You will use to send an sms or make a call from android application.

SMS Manager

SMSManager Manages operations such as sending data, text, and pdu messages.

Get this object by calling the static method SmsManager.getDefault().

Intent

An intent is an abstract description of an operation to be performed.

  • ACTION_DIAL
  • ACTION_VIEW
  • ACTION_EDIT
  • ACTION_CALL

Create new xamarin send sms call android application project.

Go to Main.axml and add components.

  • EditText(Two)
  • Button(Two)

Xamarin Send SMS,Xamarin Send SMS Call,Xamarin Send SMS Call Android,Send SMS Call Android

Next go to MainActivity.cs. Do the following steps.

  • Create variable for EditText,Button.
  • Refer id’s of EditText and Button.
  • Apply click Event on Button.
  • Use SMS Manager class to send an sms.
  • Use ACTION_CALL intent to make a call.

MainActivity.cs

namespace XamarinSMSCall
{
	[Activity(Label = "XamarinSMSCall", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity : Activity, View.IOnClickListener
	{
		
		EditText userMsg, userNum;     // Edit text variable for user message and number
		Button smsBtn, callBtn;        // sms and call button variable
		string no="";

		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Main);
			initialize();


		}
		public void initialize()
		{
			userMsg = (EditText)FindViewById(Resource.Id.msg);
			userNum = (EditText)FindViewById(Resource.Id.number);
			smsBtn = (Button)FindViewById(Resource.Id.sms);
			callBtn = (Button)FindViewById(Resource.Id.call);
			smsBtn.SetOnClickListener(this);
			callBtn.SetOnClickListener(this);
		}

		public void OnClick(View v)
		{
			switch (v.Id)
			{
				case Resource.Id.sms:
					if (!(userNum.Text.ToString().Equals("")) && !(userMsg.Text.ToString().Equals("")))
					{
						no = userNum.Text.ToString();
						string userMessage = userMsg.Text.ToString();
						SmsManager smManager = SmsManager.Default;
						// sending text message
						smManager.SendTextMessage(no, null, userMessage, null, null);
					}
					else {
						Toast.MakeText(this, "Empty Fields", ToastLength.Short).Show();
					}
					break;
				case Resource.Id.call:
					if (!userNum.Text.ToString().Equals(""))
					{
						no = userNum.Text.ToString();

						Intent callIntent = new Intent(Intent.ActionCall);
						callIntent.SetData(Android.Net.Uri.Parse("tel:"+no));
						StartActivity(callIntent);
					}

					break;
			}
		}
	}
}

At last go to Android Manifest.xml file.Add SEND_SMS,CALLPHONE permissions.

Run your xamarin send sms call android application project.

Xamarin Send SMS,Xamarin Send SMS Call,Xamarin Send SMS Call Android,Send SMS Call Android

That’s it for xamarin send sms call android  tutorial.

For Java example visit Android Codec.

Thanks.