private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxItem li = listSharing.SelectedItem as ListBoxItem; if (li != null) { switch (li.Content.ToString()) { case "Sms": Microsoft.Phone.Tasks.SmsComposeTask sms = new Microsoft.Phone.Tasks.SmsComposeTask(); sms.Body = AppResource.ResourceManager.GetString("ApplicationName"); sms.Show(); break; case "Email": Microsoft.Phone.Tasks.EmailComposeTask email = new Microsoft.Phone.Tasks.EmailComposeTask(); email.Subject = AppResource.ResourceManager.GetString("ApplicationName"); email.Body = AppResource.ResourceManager.GetString("NewSession") + " : " + "\n" + sport; email.Show(); break; case "Facebook": LoginToFacebook(); break; case "Twitter": GetTwitterToken(); break; default: break; } } listSharing.SelectedIndex = -1; }
private void ApplicationBarMenuItem_Click(object sender, EventArgs e) { Microsoft.Phone.Tasks.SmsComposeTask smsComposeTask = new Microsoft.Phone.Tasks.SmsComposeTask(); smsComposeTask.To = "555555555"; smsComposeTask.Body = emailTitle + "\n\nSent from OSArena Windows Phone App\n\n" + emailURL; ; smsComposeTask.Show(); }
private void btnSms_Click(object sender, System.Windows.RoutedEventArgs e) { if (m_tags == null) { return; } switch (m_tags.GetType().ToString()) { case "Ressive.Utils.RscTextTags_VCF": Microsoft.Phone.Tasks.SmsComposeTask sct = new Microsoft.Phone.Tasks.SmsComposeTask(); sct.To = ((RscTextTags_VCF)m_tags).PhoneNumber(0); sct.Show(); break; default: MessageBox.Show("No action defined!"); break; } }
/// <summary> /// Shows the compose SMS dialog, pre-populated with data from the supplied ChatMessage object, allowing the user to send an SMS message. /// </summary> /// <param name="message">The chat message.</param> /// <returns>An asynchronous action.</returns> public static Task ShowComposeSmsMessageAsync(ChatMessage message) { #if __ANDROID__ return(Task.Run(() => { StringBuilder addresses = new StringBuilder(); foreach (string recipient in message.Recipients) { addresses.Append(recipient + ";"); } if (addresses.Length > 0) { // trim final semicolon addresses.Length--; } Intent smsIntent = new Intent(Intent.ActionSendto, global::Android.Net.Uri.Parse("smsto:" + addresses.ToString())); smsIntent.PutExtra("sms_body", message.Body); smsIntent.AddFlags(ActivityFlags.ClearWhenTaskReset); Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(smsIntent); //Platform.Android.ContextManager.Context.StartActivity(smsIntent); })); #elif __IOS__ return(ShowComposeSmsMessageAsyncImpl(message)); #elif WINDOWS_UWP || WINDOWS_PHONE_APP Windows.ApplicationModel.Chat.ChatMessage m = new Windows.ApplicationModel.Chat.ChatMessage(); foreach (string r in message.Recipients) { m.Recipients.Add(r); } m.Body = message.Body; return(Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(m).AsTask()); #elif WINDOWS_APP || WIN32 || __MAC__ return(Task.Run(async() => { // build uri StringBuilder sb = new StringBuilder(); if (message.Recipients.Count == 0) { throw new InvalidOperationException(); } else { sb.Append("sms:"); foreach (string recipient in message.Recipients) { sb.Append(recipient + ";"); } // Remove last semi-colon if (sb.Length > 4) { sb.Length -= 1; } } // add body if present if (!string.IsNullOrEmpty(message.Body)) { sb.Append("?"); sb.Append("body=" + Uri.EscapeDataString(message.Body)); } await InTheHand.System.Launcher.LaunchUriAsync(new Uri(sb.ToString())); })); #elif WINDOWS_PHONE return(Task.Run(() => { Microsoft.Phone.Tasks.SmsComposeTask composeTask = new Microsoft.Phone.Tasks.SmsComposeTask(); composeTask.Body = message.Body; StringBuilder recipients = new StringBuilder(); foreach (string recipient in message.Recipients) { recipients.Append(recipient + ";"); } // Remove last ; if (recipients.Length > 0) { recipients.Length -= 1; } composeTask.To = recipients.ToString(); composeTask.Show(); })); #else throw new PlatformNotSupportedException(); #endif }
/// <summary> /// Shows the compose SMS dialog, pre-populated with data from the supplied ChatMessage object, allowing the user to send an SMS message. /// </summary> /// <param name="message">The chat message.</param> /// <returns>An asynchronous action.</returns> public static Task ShowComposeSmsMessageAsync(ChatMessage message) { #if __ANDROID__ return Task.Run(() => { StringBuilder addresses = new StringBuilder(); foreach (string recipient in message.Recipients) { addresses.Append(recipient + ";"); } if (addresses.Length > 0) { // trim final semicolon addresses.Length--; } Intent smsIntent = new Intent(Intent.ActionSendto, global::Android.Net.Uri.Parse("smsto:" + addresses.ToString())); smsIntent.PutExtra("sms_body", message.Body); smsIntent.AddFlags(ActivityFlags.ClearWhenTaskReset); Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.StartActivity(smsIntent); //Platform.Android.ContextManager.Context.StartActivity(smsIntent); }); #elif __IOS__ return Task.Run(() => { try { string[] recipients = new string[message.Recipients.Count]; message.Recipients.CopyTo(recipients, 0); UIApplication.SharedApplication.BeginInvokeOnMainThread(() => { MFMessageComposeViewController mcontroller = new MFMessageComposeViewController(); mcontroller.Finished += mcontroller_Finished; mcontroller.Recipients = recipients; mcontroller.Body = message.Body; UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (currentController.PresentedViewController != null) currentController = currentController.PresentedViewController; currentController.PresentViewController(mcontroller, true, null); }); } catch(Exception ex) { global::System.Diagnostics.Debug.WriteLine(ex); // probably an iPod/iPad throw new PlatformNotSupportedException(); } }); #elif WINDOWS_UWP || WINDOWS_PHONE_APP Windows.ApplicationModel.Chat.ChatMessage m = new Windows.ApplicationModel.Chat.ChatMessage(); foreach (string r in message.Recipients) { m.Recipients.Add(r); } m.Body = message.Body; return Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(m).AsTask(); #elif WINDOWS_APP return Task.Run(async () => { // build uri StringBuilder sb = new StringBuilder(); if (message.Recipients.Count == 0) { throw new InvalidOperationException(); } else { sb.Append("sms:"); foreach (string recipient in message.Recipients) { sb.Append(recipient + ";"); } // Remove last semi-colon if (sb.Length > 4) { sb.Length -= 1; } } // add body if present if (!string.IsNullOrEmpty(message.Body)) { sb.Append("?"); sb.Append("body=" + Uri.EscapeDataString(message.Body)); } await Windows.System.Launcher.LaunchUriAsync(new Uri(sb.ToString())); }); #elif WINDOWS_PHONE return Task.Run(() => { Microsoft.Phone.Tasks.SmsComposeTask composeTask = new Microsoft.Phone.Tasks.SmsComposeTask(); composeTask.Body = message.Body; StringBuilder recipients = new StringBuilder(); foreach (string recipient in message.Recipients) { recipients.Append(recipient + ";"); } // Remove last ; if (recipients.Length > 0) { recipients.Length -= 1; } composeTask.To = recipients.ToString(); composeTask.Show(); }); #else throw new PlatformNotSupportedException(); #endif }