Last active
August 29, 2017 20:26
-
-
Save tomcurran/6deeeb4781f610a0105ee634a8c9fda0 to your computer and use it in GitHub Desktop.
Xamarin Android SMS Send Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Widget; | |
using Android.OS; | |
using Android.Content; | |
using Android.Telephony; | |
using Android.Net; | |
namespace SmsTest.Android | |
{ | |
[Activity(MainLauncher = true, Icon = "@mipmap/icon")] | |
public class MainActivity : Activity | |
{ | |
const string telephoneNumber = "-------"; // TODO put telephone number here | |
EditText _editText; | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
base.OnCreate(savedInstanceState); | |
SetContentView(Resource.Layout.main); | |
_editText = FindViewById<EditText>(Resource.Id.editText); | |
FindViewById<Button>(Resource.Id.button_inapp).Click += Button_InApp_Click; | |
FindViewById<Button>(Resource.Id.button_intent).Click += Button_Intent_Click; | |
} | |
void Button_InApp_Click(object sender, System.EventArgs e) | |
{ | |
// test sending directly from app | |
for (int i = 1; i < 3; i++) | |
{ | |
SmsManager.Default.SendTextMessage(telephoneNumber, null, $"{i}. {_editText.Text}", null, null); | |
} | |
} | |
void Button_Intent_Click(object sender, System.EventArgs e) | |
{ | |
// test putting text message into SMS app | |
var smsUri = Uri.Parse($"smsto:{telephoneNumber}"); | |
var smsIntent = new Intent(Intent.ActionSendto, smsUri); | |
smsIntent.PutExtra("sms_body", _editText.Text); | |
StartActivity(smsIntent); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment