windows mobile 短信拦截

对于windows mobile的短信拦截,网上大概有两种方法:

C++:微软的SDK中提供一个Mapirule的例子。编译好mapirule.dll后,对注册表修改之类的就行了。因为我是用C#的,所以这个方法没试。

C#:通过MessageInterceptor类实现。C++也可以使用这个方法。使用这个方法方便很多,可是就是,在程序失去焦点后就不能实现拦截了。

通过网上搜索,得到解决程序失去焦点问题的方法:

参考MSDN:http://msdn.microsoft.com/en-us/bb932385.aspx

通过在注册表中建立一个持久的信息通知,这样在应用程序退出的时候,也能进行短信拦截了!

代码大致如下:


 1 MessageInterceptor _smsInterceptor = null;
 2 const string _persistentIdentifier = "Contoso.Pharmaceuticals.MessageHandlerApp";
 3 
 4 private void Form1_Load(object sender, EventArgs e)
 5 {
 6     if ( ! MessageInterceptor.IsApplicationLauncherEnabled(_persistentIdentifier))
 7     {
 8         // Persistent notification does not yet exist - must explicitly create
 9         _smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false);
10         _smsInterceptor.MessageCondition = new MessageCondition(MessageProperty.Body, 
11             MessagePropertyComparisonType.StartsWith, "Contoso Data:"false);
12         // Make the interceptor persistent
13         _smsInterceptor.EnableApplicationLauncher(_persistentIdentifier);
14     }
15     else
16     {
17         // Persistent notification already defined - create this instance using the
18         // same characteristics
19         _smsInterceptor = new MessageInterceptor(_persistentIdentifier, false);
20     }
21 
22     // Once the interceptor is created, add event handler. Whether the interceptor is constructed
23     // explicitly or constructed from the persistent notification identifier, 
24     // the event handling behavior is the same.
25     _smsInterceptor.MessageReceived += SmsInterceptor_MessageReceived_OnThread;
26 
27 }
28 
29 // Notification runs on the message-interceptor thread, not the main
30 // application thread
31 void SmsInterceptor_MessageReceived_OnThread(object sender, MessageInterceptorEventArgs e)
32 {
33     SmsMessage newMessage = e.Message as SmsMessage;
34     if (newMessage != null)
35     {
36         // Cannot interact directly with user interface - in this case
37         // using an anonymous delegate with the BeginInvoke method to
38         // to transfer control to the main application thread to update
39         // the status bar
40         statusBar1.BeginInvoke(
41             (MethodInvoker)delegate { 
42                 statusBar1.Text = "From:" + newMessage.From.Address; 
43             });
44         Debug.WriteLine(string.Format("Sender:{0} - Body:{1}", newMessage.From.Address, newMessage.Body));
45     }
46 }
47 
48 
49 // Remove persistent notification 
50 private void menuDisablePersistentNotification_Click(object sender, EventArgs e)
51 {
52     // Confirm that _smsInterceptor is a valid reference, that the current 
53     // _smsInterceptor instance is associated with the correct persistent 
54     // notification identifier, and that a persistent notification exists
55     // that has the specified identifier
56     if (_smsInterceptor != null &&
57         _smsInterceptor.ApplicationLaunchId == _persistentIdentifier &&
58         MessageInterceptor.IsApplicationLauncherEnabled(_persistentIdentifier))
59     {
60         _smsInterceptor.DisableApplicationLauncher();
61     }
62 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值