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
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.
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()
3: List<Contact> contacts = GetContacts(comboBoxCategories.SelectedItem.ToString());
5: SmsMessage smsMessage = new SmsMessage();
6: //Set the message body.
7: smsMessage.Body = textBoxSMSMessage.Text;
8:
9: foreach (Contact contact in contacts)
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.
Theme design by Jelle Druyts
Pick a theme: BlogXP BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves The Right Stuff 2.0 Tricoleur useit.com Voidclass2 BlogXP BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves The Right Stuff 2.0 Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, Chris Craft
E-mail