How to manage incoming call with OpenNetCf TAPI (Windows Mobile C

How to manage incoming call with OpenNetCf TAPI (Windows Mobile C#)
G.Morreale

Introduction

If you want to manage an incoming call you can use the windows mobile status api.
By this managed api you can get the status of many system properties: http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.status.systemproperty.aspx

But if you more than get the status by using an event handler, you must use the tapi mobile version, like the previous article I find more useful the opennetcf tapi wrapper: http://tapi.codeplex.com

Now I try to describe the way for get a call instance of an incoming call.

The example

Make a smart device c# project with a Form.

The first step like make a call as we see in the previous article is to initialize the tapi api.

        public Form1()
        {
            InitializeComponent();
            this.InitializeTelephony();
        }

        private void InitializeTelephony()
        {

            m_telephony = new Telephony();

            //Initialize the telephony class
            m_telephony.Initialize();

            //Get the cellular line with Monitor and Owner privileges
            m_line = m_telephony.CellularLine(MediaMode.InteractiveVoice, CallPrivilege.Monitor | CallPrivilege.Owner);

            //Add a new call event
            m_line.NewCall += new Line.NewCallHandler(m_line_NewCall);
        }

As you see in the code the call handler delegates the new call event to m_line_NewCall method


        /// <summary>
        /// Handles any new calls coming in/out of the phone the 
        /// </summary>
        /// <param name="call"></param>
        void m_line_NewCall(Call call)
        {
            lineSetCallPrivilege(call.Handle, CallPrivilege.Owner);
        }

        
In order to take the right privilege on the phone line you must use this coredll method:
        
        [DllImport("coredll")]
        extern static public int lineSetCallPrivilege(IntPtr hCall, CallPrivilege dwPrivilege);

 
so for example if you want to hang up all the incoming call you have to add only this line of code

        void m_line_NewCall(Call call)
        {
            lineSetCallPrivilege(call.Handle, CallPrivilege.Owner);
            call.HangUp();
        }

Also you can add a call info handler in order to monitor the call infos, for example:


        void m_line_NewCall(Call call)
        {
            lineSetCallPrivilege(call.Handle, CallPrivilege.Owner);
            call.CallInfo += new Call.CallInfoHandler(call_CallInfo);
        }


        string m_calledNumber = null;

        void call_CallInfo(Call call, CallInfoState infoState, CallInformation info)
        {
            Debug.println(info.CalledID); //print the caller id
        }

And Don't forget to shutdown the telephony instance!

        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            m_telephony.Shutdown();
        }


1 comment:

Unknown said...

How do you play a message down the to the person on the other end of the call? This would be really useful for ordering pizza!