2. messageinterceptor
For C #, it is very easy to intercept text messages, instead of those APIs in C ++, But I just tried to intercept text messages and intercept them, the subsequent operations are not easy yet.
1. Add necessary references:
Using Microsoft. windowsmobile. pocketoutlook;
Using Microsoft. windowsmobile. pocketoutlook. messageinterception;
At this time, the compilation may still fail. Check whether Microsoft. windowsmobile. pocketoutlook is referenced in the solution.AndMicrosoft. windows Mobile and Microsoft. windows Mobile. pocketoutlook. messageinterception. If you do not manually add references, you only need to use using to query them on the Internet. However, I cannot try it. You can only add references manually.
2. Add code
Messageinterceptor m_interceptor;
M_interceptor = new messageinterceptor ();
M_interceptor.messagereceived + = new messageinterceptoreventhandler (m_onmessagereceived );
// Add a handler to the messagereceived of interceptor. This is a typical observer mode. When an observer discovers a new message, the registered handler is called.
Void m_onmessagereceived (Object sender, messageinterceptoreventargs E)
{
// This function is the handler function. When the text message arrives, it will be called. These functions are also found on the Internet. I have written them into two functions, which simply requires one function.
If (E. Message is smsmessage)
M_receivesms (E. Message as smsmessage );
}
Private void m_receivesms (smsmessage)
{
// M_sbmessages is a stringbuilder and textbox1 is a textbox. I use stringbuilder to combine various text message fields and then display them in textbox.
// From
M_sbmessages.append ("from:/R/N ");
M_sbmessages.append (string. Format ("/tname: {0}/R/N", smsmessage. From. Name ));
M_sbmessages.append (string. Format ("/taddress: {0}/R/N", smsmessage. From. Address ));
// Received
M_sbmessages.append ("Received:/R/N ");
M_sbmessages.append (string. Format ("/t {0}/R/N", smsmessage. Received. tostring ()));
// Sent
M_sbmessages.append ("sent:/R/N ");
M_sbmessages.append (string. Format ("/t {0}/R/N", smsmessage. lastmodified. tostring ()));
// Body
M_sbmessages.append ("message:/R/N ");
M_sbmessages.append (string. Format ("/t {0}/R/N", smsmessage. Body ));
// Refresh
Textbox1.text = m_sbmessages.tostring ();
Textbox1.update ();
// Add a new line
M_sbmessages.append ("/R/N ");
Smsmessage. Read = true;
}
This method intercepts text messages. I still have three questions: 1. I still don't know how to prevent the system from prompting new text messages. 2. if the information is set to read, it is displayed as unread. 3. I do not know how to move text messages to other folders
This method also has a filtering class I haven't tried yet, probably it is to set whether to filter the sender or content, and then intercept the text message according to the rules, instead of all blocking.