Sunday, June 15, 2008

Today one of my readers, Paul Diston, made the following request.

Hi,
I have another idea you might be interested in. I would like to be able to type in a single SMS message and then hit the send button which would then send the same message to all my contacts that have a mobile number specified.


Thanks
Paul Diston

The thing that I really liked about Paul’s suggestion is that is cover two very important mobile development topics: one is working with contacts stored in Outlook Mobile, and the other is working with SMS messaging.

image

image Mobile SMS Contact

I changed it a little bit from Paul’s original request. I decided to incorporate a filter into the application. This way you can send SMS messages to your personal contacts, or your business contacts. You could even create a custom category. I didn’t include an option to select contacts that do not have a category assigned to them. This would be a great modification for a reader to implement. Simply add a ‘<none>’ item to the list, and if that item is selected add any contact that doesn’t have a category.

I added a ListView so that users could see the contacts they were about to text message. Another great enhancement, would be the ability to modify this listing. Just a remove option would be a great addition in functionality.

One feature I added as a polishing touch, was the live character count feature. This feature lets users know how much more text they can send. And we have found another opportunity for improvement here. I limit the text to 160 characters, but if someone entered in more text we could send X number of text messages until the complete message was delivered.

Next with have our SMS Message TextBox where we can type the message we will send. Nothing special here, but I didn’t set a MaxLength of 160 characters.

At the bottom I exposed the RequestDeliveryReport property of the SmsMessage class. What ever the user picks here will be assigned to that property.

One feature that I really love about Windows Mobile programming, that especially came in useful for this application was the Cellular Emulator.

GetContacts Code:

   1: private List<Contact> GetContacts(string category)
   2: {
   3:     List<Contact> contacts = new List<Contact>();
   4:  
   5:     ContactCollection contactsCollection = outlookSession.Contacts.Items;
   6:  
   7:     foreach (Contact contact in contactsCollection)
   8:     {
   9:         if (contact.Categories.Contains(category))
  10:         {
  11:             contacts.Add(contact);
  12:         }
  13:     }
  14:  
  15:     return contacts;
  16: }

SendSMS Code:

   1: private void SendSMS()
   2: {
   3:     List<Contact> contacts = GetContacts(comboBoxCategories.SelectedItem.ToString());
   4:  
   5:     SmsMessage smsMessage = new SmsMessage();
   6:     //Set the message body.
   7:     smsMessage.Body = textBoxSMSMessage.Text;
   8:  
   9:     foreach (Contact contact in contacts)
  10:     {
  11:         string name = string.Format("{0} {1}", contact.FirstName, contact.LastName).Trim();
  12:         string address = contact.MobileTelephoneNumber;
  13:  
  14:         if (address.Length == 0) break;
  15:  
  16:         //Add recipients.
  17:         smsMessage.Body = textBoxSMSMessage.Text;
  18:         if (name.Length == 0)
  19:             smsMessage.To.Add(new Recipient(address));
  20:         else
  21:             smsMessage.To.Add(new Recipient(name, address));
  22:         smsMessage.RequestDeliveryReport = checkBoxRequestDeliveryReport.Checked;
  23:     }
  24:  
  25:     if(smsMessage.To.Count == 0) return;
  26:  
  27:     //Send the SMS message.
  28:     smsMessage.Send();
  29: }

Download executable: mobileSMSContact.cab

Download Source Code: mobileSMSContact.zip

Feedback

One thing I decided not to do with this application is spend any time on the UI. I wanted readers to see one application that was plain Jane vanilla. Consider what you could do to this application to make it appealing to end users. Share your ideas, and maybe I’ll do them, or even better try taking the code and making the changes yourself. If you do this for the application or any other I will link to back to you so everyone can “see” and “learn” for your efforts.


Sunday, June 15, 2008 02:10:00 (Eastern Standard Time, UTC-05:00)  #    Comments [2]  |  Trackback Tracked by:
"30 Days of .NET [Windows Mobile Applications] - Week Two" (Chris Craft's Blog) [Trackback]

Sunday, June 15, 2008 01:55:58 (Eastern Standard Time, UTC-05:00)
A request/proposal for your next "30 days os .NET" application:

A simple list of all the elements that can provide positioning with our PDA.

1. List of detected WiFi networks
2. List of detected Bluetooth devices
3. From the phone network... Actual Cell ID
4. Coordinates from the GPS

Checking the availability of each device (Phone, GPS, BT, WIFI).
And activating required devices if they are turned off.
But turning it off once completed the operations.



Marcos
Sunday, June 15, 2008 05:29:41 (Eastern Standard Time, UTC-05:00)
You could simplify your GetContacts code by using the Restrict method of the ContactCollection to add a restriction to your specific category rather than looping through the entire collection e.g.

ContactCollection contactsCollection = outlookSession.Contacts.Items.Restrict("[Categories] = \"" + category + "\"");

Peter

Comments are closed.

Theme design by Jelle Druyts

Pick a theme: