windows mobile 短信拦截(转)
http://www.cnblogs.com/simalone/archive/2010/03/14/1601211.html
经过近段时间不断在网的搜索,终于今天下午有所斩获了:
对于windows mobile的短信拦截,网上大概有两种方法:
C++:微软的SDK中提供一个Mapirule的例子。编译好mapirule.dll后,对注册表修改之类的就行了。因为我是用C#的,所以这个方法没试。
C#:通过MessageInterceptor类实现。C++也可以使用这个方法。使用这个方法方便很多,可是就是,在程序失去焦点后就不能实现拦截了。
通过网上搜索,得到解决程序失去焦点问题的方法:
参考MSDN:http://msdn.microsoft.com/en-us/bb932385.aspx
通过在注册表中建立一个持久的信息通知,这样在应用程序退出的时候,也能进行短信拦截了!
代码大致如下:
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 }
MessageInterceptor简直就是个笑话,高手菜鸟都来看看:http://topic.csdn.net/u/20071204/17/c8946432-a979-4e8d-ba8d-f881a15bb7a0.html?seed=1883745506
关于拦截后的对不需要拦截的写到SIM,可以参考
http://www.cnblogs.com/appleseeker/archive/2008/03/29/1129031.html
虽然到目前观摩了很多关于windows mobile的短信防火墙的文章,但目前为止尚未找到对于C#的完善解决方法。真是cupTools呀!