Use SmsManager to open the default sms app - c#

I am building a Xamarin Android application (API version>=23) that should call the SMS default application with a prefilled-in number and prefilled-in text.
I figure out how to send the SMS using SmsManager
SmsManager.Default.SendTextMessage("Number", null, "Text", null, null);
The above line send the SMS text directly after the user grants the permission to the app. Is there a way to open the default SMS app instead with prefilled in destination number and text, and let the user press send ?
Any help would be appreciated.

Setting up an Intent can bring up the default SMS massager app:
var intent = new Intent(Intent.ActionSendto);
intent.SetData(Android.Net.Uri.Parse("smsto:" + "555-555-1212"));
intent.PutExtra("sms_body", "StackOverflow rocks");
StartActivity(intent);
It is doubtful that there is no SMS registered app, but you can use the Intent that you populated to check for for which app/activity will launched:
var packagename = intent.ResolveActivity(PackageManager)?.PackageName;

Related

DSharpPlus send an embed to a specific channel?

I'm new to working with discord bots and I was wondering if anybody knew a way to send embedded messages to specific channels. The only way I've found so far to send one is to use RespondAsync which just directly replies to whoever issues the command in the same channel. The purpose of my bot is to create automated link directories in read only channels and the command will just refresh them. Having trouble finding much Dsharpplus c# examples, and I'm terrible at making sense of documentation. Any help would be appreciated.
await ctx.RespondAsync(embed);
this is what I've been using to send my embeds for testing purposes, but like I said I'd like to send it in a way that it posts to a specified channel
You just need to get the DiscordChannel object of the channel(s) you want to send the embed. You can get the ID of the channel via right-click in Discord and "Copy ID"
DiscordChannel channel = await _client.GetChannelAsync(ID_OF_CHANNEL);
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Color = DiscordColor.SpringGreen,
Description = "Good to see you!",
Title = "Hello World"
};
await channel.SendMessageAsync(embed: embed);
The DiscordGuild class also has GetChannelAsync you can use.

Twilio. Set Fax Webhook programmatically using the API

My application wants to dynamically purchase new FAX numbers when the pool of serviced users exceeds a certain amount. I am able to do this programmatically from API like this (C#):
using Twilio;
using Twilio.Rest.Fax.V1;
using Twilio.Rest.Api.V2010.Account;
var incomingPhoneNumber = IncomingPhoneNumberResource.Create(
statusCallback: new Uri("https://myapp.co/api/v1/fax/twiliostatus"),
statusCallbackMethod:Twilio.Http.HttpMethod.Post,
pathAccountSid:"xxx",
phoneNumber: new Twilio.Types.PhoneNumber(numbers[i].PhoneNumber)
);
...but I don't see any mechanism for setting the value corresponding to the "A Fax Comes In" webhook (where I set method and URI) in the portal. Is there a way I can set this from the API?
thanks in advance!
It looks like the attribute you need to set is voiceReceiveMode.
IncomingPhoneNumber resource
The configuration parameter for the new phone number to receive incoming voice calls or faxes. Can be: fax or voice and defaults to voice.

How to use BroadcastReceiver in Xamarin with C #?

I need to generate a notification when the app is in the background, but I'm not sure how to start Broadcastreceiver
There are two ways:
1. LocalBroadcastManager will send messages only to your application
Intent message = new Intent("com.xamarin.example.TEST");
// If desired, pass some values to the broadcast receiver.
intent.PutExtra("key", "value");
Android.Support.V4.Content.LocalBroadcastManager.GetInstance(this).SendBroadcast(message);
2. Context.SendBroadcast methods will send messages to the entire system
Intent message = new Intent("com.xamarin.example.TEST");
// If desired, pass some values to the broadcast receiver.
intent.PutExtra("key", "value");
context.SendBroadcast(intent);
from Xamarin guide

How to Send SMS on Xamarin.Forms

I am developing Xamarin.Forms project, iOS, Android and Windows Phone.
My app ask the user to enter text Message and Phone number then on submit, I need to send SMS to the phone number.
I prefer to have a single implementation for all platforms.
You can use this open source plugin Xam.Plugins.Messaging
https://github.com/cjlotz/Xamarin.Plugins
This is the provided example (from https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Details.md ) :
// Make Phone Call
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall)
phoneDialer.MakePhoneCall("+272193343499");
// Send Sms
var smsMessenger = CrossMessaging.Current.SmsMessenger;
if (smsMessenger.CanSendSms)
smsMessenger.SendSms("+27213894839493", "Well hello there from Xam.Messaging.Plugin");
var emailMessenger = CrossMessaging.Current.EmailMessenger;
if (emailMessenger.CanSendEmail)
{
// Send simple e-mail to single receiver without attachments, bcc, cc etc.
emailMessenger.SendEmail("to.plugins#xamarin.com", "Xamarin Messaging Plugin", "Well hello there from Xam.Messaging.Plugin");
// Alternatively use EmailBuilder fluent interface to construct more complex e-mail with multiple recipients, bcc, attachments etc.
var email = new EmailMessageBuilder()
.To("to.plugins#xamarin.com")
.Cc("cc.plugins#xamarin.com")
.Bcc(new[] { "bcc1.plugins#xamarin.com", "bcc2.plugins#xamarin.com" })
.Subject("Xamarin Messaging Plugin")
.Body("Well hello there from Xam.Messaging.Plugin")
.Build();
emailMessenger.SendEmail(email);
}
Microsoft now has this feature in their new all-encompasing https://learn.microsoft.com/en-us/xamarin/essentials NuGet package.

Send sms Silently in WP8

I was trying to send sms to a group of contacts via SmsComposeTask class.
But this class's Show() method only composes message in message app. I also want my code to send those texts automatically. Please help!!
Here is what i am using:
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = recipients; // recipients is the group of contacts
smsComposeTask.Body =
"Hello! This is a test sms message!";
smsComposeTask.Show();
See: http://social.msdn.microsoft.com/Forums/wpapps/en-us/85dc6ef5-98a9-4a17-a5f0-171372d8d9a3/how-to-send-sms-from-a-windows-phone-page
using Microsoft.Phone.Tasks;
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "2065550123"; smsComposeTask.Body = "Your SMS
text";
smsComposeTask.Show();
After that a dialog will be show asking the
user whether to send the message.
You cannot silently send an SMS
Also: https://developer.nokia.com/Community/Wiki/How_to_send_an_SMS_in_Windows_Phone
Note: In contrast to Symbian, Windows Phone does not allow you to send
sms "directly" or "silently" from your own app. As soon as sms sending
initiation code below is executed the native sms editor app will be
launched, giving the user the option to send the message or not.
I image this is done so that rouge apps can't send out a bunch of texts that will cost someone money.

Categories