Windows Mobile .Net CF中电话状态的捕获

    技术2024-07-22  61

    Windows Mobile .Net CF中电话状态的捕获
    发布时间: 2009-9-11 9:54:50    被阅览数: 334次    文字大小:〖 大 中 小 〗

    有些朋友在BBS上或者在我的blog上面留言问如何得知电话的接通状态,比如说接通,挂断或者挂起(等待)。比较传统的方法是使用,Windows CE的Telephony API(TAPI),不过你可能要写比较麻烦的代码,可能涉及到一些回调函数。可以参阅SDK下面的cellcore例子。在Windows Mobile 5以后的机器上,你可以使用一些TAPI的Wrapper,在托管代码中实现它的相应功能。比如这里要提的SystemProperty.PhoneCallTalking和SystemProperty.PhoneActiveCallCount。

    下面的程序演示了如何利用他们来获得电话状态:        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);             }         }   运行效果: 来电 接电话 挂起 这里订阅的两个事件都很有用,callState.Changed是用来判断电话是否正在通话中,一旦状态发生改变,该事件被触发,当正在通话时,事件参数的值变为true,挂断时,事件参数的值为false。callCount.Changed是当前接通的线路数量,有来电时+1(默认为零),挂断时-1。 不过我发现这里有个问题,也许是CF的BUG。当我移除或者替换MessageBox.Show("Call Incoming...");这一句的时候,callState.Changed似乎永远不会被触发了。我使用的使WM6 pro Emulator + Cellular Emulator做的测试。在我的设备上(Intel Xscale 416mhz, WM5 PPC phone,.Net CF 3.5)测试,按接听电话的键之后立即出现Phone对话框,仍然有不能触发callState.Changed的问题,似乎是事件监听的线程被阻塞, 这是否是CF的BUG还有待进一步测试。
    最新回复(0)