Abstract: This article describes how For Windows Mobile 5.0 Obtain the phone status in the above system, such as connection or hanging up, C # Description.
Keywords
Windows Mobile,. Net CF, phonestate, systemstate, C #, bug
I wrote an article earlier:
[Cf. Skills]In. NET Compact frameworkObtain and shield incoming callsThis article is part of its append.
some friends BBS on or on my blog the above message asks you how to know the call status, such as connection, ( wait ) . the traditional method is to use, Windows CE Telephony API (TAPI) , however, you may need to write Code , which may involve some callback functions. See SDK cellcore example.
On Windows Mobile 5 you can use TAPI wrapper to implement its functions in managed code. for example, systemproperty. phonecalltalking and systemproperty. phoneactivecallcount .
The followingProgramDemonstrate how to use them to get the phone status:
Public Void listencall ()
{
Callstate = New Systemstate (systemproperty. phonecalltalking );
Callcount = New Systemstate (systemproperty. phoneactivecallcount );
Callstate. Changed + = New Changeeventhandler (callstate_changed );
Callcount. Changed + = New Changeeventhandler (callcount_changed );
}
Void callcount_changed ( Object Sender, changeeventargs ARGs)
{
If (ARGs. newvalue! = Null && ( Int ) Args. newvalue! = 0 )
MessageBox. Show ( " Call incoming " );
}
Void callstate_changed ( Object Sender, changeeventargs ARGs)
{
If (ARGs. newvalue! = Null)
{
String State = (( Int ) Args. newvalue) = 1 ? " Talking " : " Hang up " ;
MessageBox. Show (State );
}
}
Running effect:
Incoming call
answer phone
suspend
both subscribed events are useful, callstate. changed this event is used to determine whether a call is in progress. Once the call status changes, this event is triggered. When the call is in progress, the event parameter value is true , the event parameter value is false . callcount. changed is the number of currently connected lines. When an incoming call is available + 1 ( default value: 0 ) , -1 .
But I found a problem here, maybe it isCfOfBug. When I remove or replaceMessageBox. Show ("Call incoming ...");In this sentence,Callstate. ChangedIt seems that it will never be triggered. I usedWm6 pro emulator + cellular emulatorTest. On my device(Intel XScale 416 MHz, wm5 PPC phone,. Net CF 3.5)Test, press the answer key and then immediately displayPhoneDialog box, which cannot be triggeredCallstate. ChangedIt seems that the thread of the event listening is blocked. Is this true?CfOfBugFurther tests are pending.
Download sample here: Sample download