This blog is moved to a new home - https://christianhelle.com
Thursday, January 20, 2011
Multi-platform Mobile Development - Sending SMS
This is a task that pretty much every mobile device can do, or at least any mobile phone can do. In this short post on multi-platform mobile development I would like to demonstrate how to send an SMS or launch the SMS compose window in a mobile application.
I'm going to demonstrate how to use the messaging API's of the following platforms:
Android
Windows Phone 7
Windows Mobile 5.0 (and higher) using .NET Compact Framework
Windows Mobile using the Platform SDK (Native code)
Android
There are 2 ways of sending SMS from an Android application: Launching the Compose SMS window; Through the SmsManager API. I figured that since this article is supposed to demonstrate as many ways as possible for sending SMS that I create a helper class containing methods that I think would be useful or at least convenient to have.
Here's a SMS helper class for Android that I hope you would find useful.
Before your Android application can send SMS it needs the right permissions for it. Add the SEND_SMS permission your AndroidManifest.xml
Here are some examples on how to use the SMS helper class defined above from within an Activity class:
Windows Phone 7
This platform unfortunately doesn't provide as vast a API collection compared to Android and Windows Mobile. To send an SMS in Windows Phone 7, you will have to use the SMS Compose page in the built-in messaging application. To launch this we call the Show() method in SmsComposeTask.
Here's how to use SmsComposeTask
SmsComposeTask launcher = newSmsComposeTask();
launcher.To = "+45 12 34 56 78";
launcher.Body = "Multi-platform Mobile Development";
launcher.Show();
Windows Mobile 5.0 (and higher) using .NET Compact Framework
Sending an SMS in this platform is just as easy as doing so in Windows Phone 7. Windows Mobile provides native API's for the Short Messaging System, these methods are exposed as C type methods in a DLL called sms.dll. Aside from the SMS API, the platform also offers another API called the Messaging API (CE MAPI) for sending SMS, MMS, and Emails. Microsoft has provided managed wrappers for these and many other API's to make the life of the managed code developer a lot easier.
To send an SMS in Windows Mobile 5.0 (and higher) we use the SmsMessage object. There are 2 ways of accomplishing this: Using the Send() method of the SmsMessage class; Sending the SMS using the Compose SMS application
Here's a snippet on how to send SMS using the Send() method
The code above depends on 2 assemblies that must be referenced to the project:
Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.PocketOutlook.dll
It is also possible to P/Invoke the SMS API through sms.dll, but this requires a slightly more complicated solution. In the next section, I will demonstrate how use the SMS API in native code. This should give you an idea on how to use the SMS API if you would like to go try the P/Invoke approach.
Windows Mobile using the Platform SDK (Native code)
Probably not very relevant for most modern day managed code developers but just to demonstrate as many ways to send SMS in as many platforms as possible I'd like to show how to send SMS in native code using the Windows CE Short Message Service (SMS) API.
Here's a sample C++ helper class for sending SMS using the Platform SDK
The code above requires the that the project is linked with sms.lib, otherwise you won't be able to build.
Here's a snippet of how to use the SMS helper class defined above:
SmsMessage *sms = new SmsMessage(L"+14250010001", L"Multi-platform Mobile Development");
sms->Send();
delete sms;
For those who don't know what +14250010001 is, this is the phone number of the Windows Mobile emulator. For testing SMS functionality on the emulator, you can use this phone number.
That's it for now. I hope you found this article interesting.
Hello, I would like to create an app, that sends an sms from a website according to the parameters that the user has chosen, would you be able to guide me on how to go about this, as in what is required in terms of hardware and software
What are the advantages and disadvantages of "multi platform development"?
ReplyDeleteHello, I would like to create an app, that sends an sms from a website according to the parameters that the user has chosen, would you be able to guide me on how to go about this, as in what is required in terms of hardware and software
ReplyDeleteThanks that some how i landed here...
ReplyDeleteI learned new techniques..