次の方法で共有


How to: Monitor calls on Windows Mobile using C#

Someone just sent me a mail and asked if we had any C# samples / source code for monitoring status of incoming and outgoing calls. It all really depends on what you want to do with these calls, are you just trying to get the status? or trying to capture the audio? they're two very different scenarios.

here's a list of System Properties that you can return using Microsoft.WindowsMobile.Status assembly. I guess the segment that you're most interested in is this:

Phone1xRttCoverage
Gets a value indicating whether the phone currently has 1xRTT coverage.

PhoneActiveCallCount
Gets the number of active phone calls.

PhoneActiveDataCall
Gets a value indicating whether the phone has an active cellular data connection.

PhoneBlockedSim
Gets a value indicating whether the Subscriber Identity Module (SIM) is blocked.

PhoneCallBarring
Gets a value indicating whether the call barring feature is enabled.

PhoneCallCalling
Gets a value indicating whether the phone is currently attempting to connect an outgoing call.

PhoneCallForwardingOnLine1
Gets a value indicating whether call forwarding is enabled on line 1.

PhoneCallForwardingOnLine2
Gets a value indicating whether call forwarding is currently active on line 2.

PhoneCallOnHold
Gets a value indicating whether a phone call is currently on hold.

PhoneCallTalking
Gets a value indicating whether there is currently a phone call in the talking state.

PhoneCellBroadcast
Gets the cell broadcast message

PhoneConferenceCall
Gets a value indicating whether a conference call is currently in progress.

PhoneGprsCoverage
Gets a value indicating whether the phone currently has GPRS coverage.

PhoneHomeService
Gets a value indicating whether the phone is currently registered on its home network.

PhoneIncomingCall
Gets a value indicating whether there is an incoming (ringing) call.

PhoneIncomingCallerContact
Gets the Contact that matches the Caller ID.

PhoneIncomingCallerContactPropertyID
Gets the CEPROPID of the property that matches the Caller ID, for example, PIMPR_HOME_TELEPHONE_NUMBER.

PhoneIncomingCallerContactPropertyName
Gets the name of the property that matches the Caller ID, e.g. "h" for "Home Telephone".

PhoneIncomingCallerName
Gets the name of the person who is currently placing the incoming call.

PhoneIncomingCallerNumber
Gets the incoming call's phone number (Caller ID).

PhoneInvalidSim
Gets a value indicating whether the Subscriber Identity Module (SIM) is invalid.

PhoneLastIncomingCallerContact
Gets the Contact that matches the last Caller ID.

PhoneLastIncomingCallerContactPropertyID
Gets the CEPROPID of the property that matches the last Caller ID, for example, PIMPR_HOME_TELEPHONE_NUMBER.

PhoneLastIncomingCallerContactPropertyName
Gets the name of the property that matches the last Caller ID, e.g. "h" for "Home Telephone".

PhoneLastIncomingCallerName
Gets the name of the last caller to place an incoming call.

PhoneLastIncomingCallerNumber
Gets the last incoming call's phone number (Caller ID).

PhoneLine1Selected
Gets a value indicating whether line 1 is selected.

PhoneLine2Selected
Gets a value indicating whether line 2 is selected.

PhoneMissedCall
Gets a value indicating whether there was a new missed call.

PhoneMissedCalls
Gets the number of missed phone calls.

PhoneMultiLine
Gets a value indicating whether the phone supports multiple lines.

PhoneNoService
Gets a value indicating whether the phone is not currently connected to a network.

PhoneNoSim
Gets a value indicating whether the Subscriber Identity Module (SIM) is installed in the mobile device.

PhoneOperatorName
Gets the name of the mobile operator (i.e., the mobile phone company, or carrier).

PhoneProfile
Gets the non-localized name of the current sound profile. For example, "Normal", "Silent", "Car", "Headset", "Loud", "Meeting", or "Speakerphone". (Smartphone only)

PhoneProfileName
Gets the localized name of the current sound profile. (Smartphone only)

PhoneRadioOff
Gets a value indicating whether the phone's radio is turned off.

PhoneRadioPresent
Gets a value indicating whether the mobile device has a phone.

PhoneRingerOff
Gets a value indicating whether the phone's ringer is off (i.e., if it rings and/or vibrates).

PhoneRoaming
Gets a value indicating whether the phone is currently in roaming mode.

PhoneSearchingForService
Gets a value indicating whether the phone is currently searching for service on a network.

PhoneSignalStrength
Get the phone signal strength, expressed as a percentage of full strength.

PhoneSimFull
Gets a value indicating whether the Subscriber Identity Module (SIM) memory is full.

PhoneTalkingCallerContact
Gets the contact who is on the active phone call.

PhoneTalkingCallerContactPropertyID
Gets the CEPROPID of the property of the contact who is on the active phone call, for example, PIMPR_HOME_TELEPHONE_NUMBER.

PhoneTalkingCallerContactPropertyName
Gets the name of the property of the contact who is on the active phone call, e.g. "h" for "Home Telephone".

PhoneTalkingCallerName
Gets the name of the person you are talking to on the phone. This value is not set when you are talking on a conference call.

PhoneTalkingCallerNumber
Gets the currently connected caller's phone number.

In order to return the status of these properties, you can use this simple code (as an example):

 InitializeComponent();
SystemState _PhoneRoaming = new SystemState(
                            SystemProperty.PhoneRoaming);


_PhoneRoaming.Change += new ChangeEventHandler(
                        _PhoneRoaming_Changed);


void _PhoneRoaming_Changed(object sender, ChangeEventArgs args)
{
   throw new Exception("The method or operation is not implemented.");
}

void _PhoneRoaming_Changed(object sender, ChangeEventArgs args)
{
   if (SystemProperty.PhoneRoaming == false)
   {
      // Perform data network access
   }
}

How do you debug applications that uses the phone network under an emulator?

There's a tool that ships with the SDK called FakeRIL or (Fake Radio Interface Layer) to simulate SMS and phone calls without actually having a cell network. Handy when using emulators for development. Barry Bond who used to work for the Mobile Team was the developer for the Windows Mobile emulators and he made a few posts and presented sessions on how you can use FakeRIL, here and here. Watch out for the "new version" when the new SDK is released, it has a lot more features than the old FakeRIL. When? Soon :)

Jim Wilson has also written two articles on programming the State and Notification Broker. Here's a BIG list of sample code for programming on Windows Mobile 5.0

Hope that helps.

 

  * UPDATE: Daniel Moth has a Channel9 Video about using the State and Notification Broker. Check it out.

Comments

  • Anonymous
    February 06, 2007
    PingBack from http://jalansutera.com/dog-training/2007/02/06/how-to-monitor-calls-on-windows-mobile-using-c/

  • Anonymous
    February 06, 2007
    Nice, ...also of interest may be my screencast on using the S & NB :-) http://channel9.msdn.com/ShowPost.aspx?PostID=271892

  • Anonymous
    January 30, 2008
    I want to develop an application to keep check on the cost of my outgoing calls and sms. Please give some sample code how to monitor outgoing calls

  • Anonymous
    April 10, 2008
    See the following article by Windows Mobile MVP Peter Foot that explains how to programmatically invoke the speakerphone using managed code. http://www.peterfoot.net/ProgrammaticallyActivatingSpeakerphone.aspx Thanks, Mike

  • Anonymous
    September 14, 2008
    I have a WM6 based phone and whwnever i'm calling someone or recieving a call, the display times out. i want the display to stay on when a phone call i going on. Is it possible to register a program to ie. incomming call like i can register a app to the MessageInterceptor?

  • Anonymous
    September 28, 2008
    Thanks for your tips. Most helpful, esp. for WM6 newbie like me. This may sound awfully trivial but where can I find some C# code snippet on how to determine the device's phone number? Thanks in advance and Cheers! --VVX

  • Anonymous
    October 04, 2008
    Hello VVX Try systemState.OwnerPhoneNumber -RP

  • Anonymous
    October 13, 2008
    systemState.OwnerPhoneNumber only works if the user has entered that into his profile. It doesn't get the number from the SIM. Is that possible?

  • Anonymous
    October 28, 2008
    This is what I did: public MainForm()        {            InitializeComponent();            SystemState _PhoneRoaming = new SystemState(                            SystemProperty.PhoneRoaming);            _PhoneRoaming.Changed += new ChangeEventHandler(_PhoneRoaming_Changed);        }        void _PhoneRoaming_Changed(object sender, ChangeEventArgs args)        {            if (SystemProperty.PhoneRoaming == false)            {                // Perform data network access            }        } Why do I get Error 1 Operator '==' cannot be applied to operands of type 'Microsoft.WindowsMobile.Status.SystemProperty' and 'bool'

  • Anonymous
    December 22, 2008
    first convert it to int: int _phoneroaming=SystemProperty.PhoneRoaming; if (_phoneroaming==0)     {//0=false     //1=true     // Perform data network access     }

  • Anonymous
    March 11, 2009
    Hi, How to programatically determine the GPRS data usage

  • Anonymous
    October 05, 2009
    If you want to go deeper with a tapi wrapper take a look to: http://programmaremobile.blogspot.com/2009/10/how-to-manage-incoming-call-with.html It explain by an example how to manage an incoming call using a tapi wrapper. Hope to be welcome!

  • Anonymous
    April 24, 2010
    i have a proyect  with is a app that gets phone connection information and sends if as an SMS Phone information battery Status Signal Status Connection status  "as in where is the cell phone conected as in conection ID" Rssi Tx power Rx power FER forward error correcion BTS SID Help Diegorafael@hotmail.com