Click here to Skip to main content
Click here to Skip to main content
Go to top

Send SMS and make Calls with MyPhoneExplorer

, 2 May 2014
Rate this:
Please Sign up or sign in to vote.
An easy way to send SMS and make Phone calls with C# using the Application MyPhoneExplorer

Introduction

During my work in a Logistic Company we tried dusends of times to make an Application or an funktion in our ERP Application to easely send SMS. We tryed sending AT commands to phones or SIM modems, syncing with Outlook explorer and online Gateways but every of thoes solutions had something that made it not good for practical use. The common reason was that it didn´t work 100% like it should what means that the SMS message went trought the code/app/online servise but never arived to the recepient Frown | :( without any error message shown. Situations like this are in a Logistik Company a small Supergau. For serveral months our Disponent manager showd my an application that he found called MyPhoneExploere. More info about that are here. He told me that the dispoets are using now that app and asked me if I could integrate it in our ERP Applicaion for Order management. At the beggining I toght "no way" - It´s an external application, i don´t thing they made an API for external contol BUT after fuve minutes on Google and a simple question there it was. A way to control the functions of the app from external calls Smile | :) In couple of minutes the code was writen and several minutes later integrated in our ERP. Now after this solution worked for us several months with an 100% eficiense (how the disponemts explained to me Smile | :) ) I want to share it woth the comunity.

Beside that the Application MyPhoneExplorer is realy a genious small app that is totaly free and easy to use. I´m not trying to make marketing or something. But for is it works likw a sharm Big Grin | :-D

The Code

Everithing that is needet to ake it work is that the Application MyPhoneExplorer is instaled, that it is runing and that a phone is connected with it. If we use Bluetooth the phone will be automaticaly connected if we are near the PC Wink | ;) as I sead - a great little app Big Grin | :-D

The code we use to start the actions we store in a small static class called MyPhoneExplorer. The class has this 2 Properties that are crutial for the functionality:

  public static string MyPhoneExplorerApplicationName
        {
            get
            {
                return "MyPhoneExplorer";
            }
        }

        public static string MyPhoneExplorerFullPath
        {
            get
            {
                foreach (Process clsProcess in Process.GetProcesses())
                {
                    if (clsProcess.ProcessName.Contains(MyPhoneExplorerApplicationName))
                    {
                        return clsProcess.Modules[0].FileName;
                    }
                }
                MessageBox.Show("MyPhoneExplorer ist nicht gestarted!", "MyPhoneExplorer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return string.Empty;

            }
        } 

The first one is just a static string. It could also be a const but who cares Wink | ;)

The second one is a string that returns us the ful path of the MyPhoneExploere application. The greate thing is that we don´t care "where" it is instaled because we get the path from the MyPhoneExplorer proccess. If the application is not runing we inform the user about that. If the application is not installed it´s the problem of the user if he tryes to start an application that is not installed Wink | ;) Of course this could be expanded that the message shows a link where to download the app or a link to a help how to use the app.

The next part of our class are 3 methods:

   public static bool SendSMS(string phoneNumber, string messageText)
        {
            string fileName = MyPhoneExplorerFullPath;
            if (fileName != string.Empty)
            {
                string arguments = String.Format(@" action=sendmessage savetosent=1 number={0} text=""{1}""", phoneNumber, messageText.Replace('"', '*'));
                StartPhoneExplorerWithArguments(fileName, arguments);
                return true;
            }
            return false;
        }

        public static void CallPhoneNumber(string phoneNumber)
        {
            string fileName = MyPhoneExplorerFullPath;
            if (fileName != string.Empty)
            {
                string arguments = String.Format(@" action=dial number={0}", phoneNumber);

                StartPhoneExplorerWithArguments(fileName, arguments);
            }

        }

        private static void StartPhoneExplorerWithArguments(string fileName, string arguments)
        {
            Process MyPhoneExplorer = new Process();
            MyPhoneExplorer.StartInfo.FileName = fileName;
            MyPhoneExplorer.StartInfo.Arguments = arguments;
            MyPhoneExplorer.Start();
        }
           

The last one is used to call the MyPhoneApplication with some arguments. We have it just to stay DRY.

The first method is used to send SMS messages. It recieves a phone number and the text message. The greate magic in this class is that we just get our Path of the MyPhoneExplorer application and generate the arguments string and at then call the last method.

EDIT: In the argument generation the massageText has a Replace that replaces the " chars to an *. The reason for that is that the " char interupts the argument parsing to the application causing that only the part of the message to " will be send and everithing after it will be just lost.

EDIT: The first method is turned to a bool. It returns true if the SMS was send and false if not. This way we can use it like this: (a code snipped from our ERP)

            if (MyPhoneExplorer.SendSMS(txtPhoneNumber.Text, txtMessageText.Text))
            {
                SMSSendMessages tblSendMessages = new SMSSendMessages(this, null);
                tblSendMessages.SaveSendMessage(User.ID, (int)cboDriverPhoneID.SelectedValue, txtPhoneNumber.Text, txtMessageText.Text);
                Close();
            } 

The second method does just the same thing generating only a different argument string.

And that is all it takes to work with it.

The Class MyPhoneExplorer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows.Forms;

namespace ICS.EnterpriseResourcePlaning
{
    public static class MyPhoneExplorer
    {

        public static string MyPhoneExplorerApplicationName
        {
            get
            {
                return "MyPhoneExplorer";
            }
        }

        public static string MyPhoneExplorerFullPath
        {
            get
            {
                foreach (Process clsProcess in Process.GetProcesses())
                {
                    if (clsProcess.ProcessName.Contains(MyPhoneExplorerApplicationName))
                    {
                        return clsProcess.Modules[0].FileName;
                    }
                }
                MessageBox.Show("MyPhoneExplorer ist nicht offen!", "MyPhoneExplorer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return string.Empty;

            }
        }

        public static bool SendSMS(string phoneNumber, string messageText)
        {
            string fileName = MyPhoneExplorerFullPath;
            if (fileName != string.Empty)
            {
                string arguments = String.Format(@" action=sendmessage savetosent=1 number={0} text=""{1}""", phoneNumber, messageText.Replace('"', '*'));
                StartPhoneExplorerWithArguments(fileName, arguments);
                return true;
            }
            return false;
        }

        public static void CallPhoneNumber(string phoneNumber)
        {
            string fileName = MyPhoneExplorerFullPath;
            if (fileName != string.Empty)
            {
                string arguments = String.Format(@" action=dial number={0}", phoneNumber);

                StartPhoneExplorerWithArguments(fileName, arguments);
            }

        }

        private static void StartPhoneExplorerWithArguments(string fileName, string arguments)
        {
            Process MyPhoneExplorer = new Process();
            MyPhoneExplorer.StartInfo.FileName = fileName;
            MyPhoneExplorer.StartInfo.Arguments = arguments;
            MyPhoneExplorer.Start();
        }

    }
}

Using the code

To send a SMS message we just use this code:

MyPhoneExplorer.SendSMS(txtPhoneNumber.Text, txtMessageText.Text); 

In this example the phone number is stored in a TextBox txtPhoneNumber and the message in the txtMessageText TextBox.

To dial a phone number we use this code:

MyPhoneExplorer.CallPhoneNumber(txtPhoneNumber.Text);  

Interesting is that if we make a call an dialog window is shown on the desktop where we can control the call.

Points of Interest

Besides this two actions there could be more done. We use only this two but if someone wants more it surrely could be done.

History

02.05.2014 - version 1.

02.05.2014 - version 2. txtMessage replacement added

02.05.2014 - version 3. the SendSMS method is turned to an bool

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

TarikHuber
Engineer ICS Logistik & Transport GmbH
Germany Germany
Born in Bosnia and Herzegowina where I studied Traffic and Communication in the University of Sarajevo. After the Bachelor, found a Job in a Logistic Company in Germany where I live and work now as an Software developer for our Company needs. Even if my studying has not mutch to do with it. Working now on my Master but it isn´t interesting as programing Wink | ;) so it could take couple of years to finish that boring thing.
 

With programming I started as an hoby at work. For now I have almost 2 years programing experience. First with excel then VBA in Excel. That growed up to VBA with Access and a first Access DB. Then an SQL Server camed in and VBA with Access could not handle it. The next move was of cource VB.Net but with Visual Studio I cam in contact with C# and fel in love with it Smile | :)
 
I also wisited the Android world and made some small Android Apps for our drivers. Nice this Java Universe Wink | ;) it has lots of potentials Smile | :)

Comments and Discussions

 
SuggestionSpelling Pinmember_Noctis_2-May-14 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 2 May 2014
Article Copyright 2014 by TarikHuber
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid