监视来到的短消息例子

监视来到的短消息例子

 

这个例子是按照监视来到的短消息,然后按照提取短消息的内容,我们可以按照里面的内容
让程序做些动作,本个例子是发送你的未读的SMS,MAIL,MMS的数量,由此可以推开得到一些
其他的应用。。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.Telephony;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using Microsoft.WindowsMobile.Status;
// using Microsoft.WindowsMobile.Status.SystemState;

namespace AppDemo
{
public partial class Form1 : Form
{
private OutlookSession AppSession;
private OutlookSession SmsSession;
private AppointmentCollection AppAppts;
private ListViewItem lviAppt;
private ListViewItem smsItem;
private MessageInterceptor interceptor;
public Form1()
{
InitializeComponent();
interceptor
= new MessageInterceptor(InterceptionAction.Notify);
interceptor.MessageReceived
+= new MessageInterceptorEventHandler(interceptor_MessageReceived);
}


private void button1_Click(object sender, EventArgs e)
{
AppSession
= new OutlookSession();
AppAppts
= AppSession.Appointments.Items;
foreach (Appointment appt in AppAppts)
{
lviAppt
= new ListViewItem();
lviAppt.Text
= appt.Start.ToShortDateString();
lviAppt.SubItems.Add(appt.Start.ToShortTimeString());
lviAppt.SubItems.Add(appt.Subject);
lvAppt.Items.Add(lviAppt);
}

AppSession.Dispose();
}


private void button2_Click(object sender, EventArgs e)
{
Phone phone
= new Phone();
try
{
phone.Talk(
13425173242);
}

catch
{
MessageBox.Show(
Can’t Dailing…);
}

}


private void button3_Click(object sender, EventArgs e)
{
SmsSession
= new OutlookSession();

//SmsAccount sms ;
smsItem = new ListViewItem();
smsItem.Text
= (String)SmsSession.SmsAccount.Name;
lvAppt.Items.Add(smsItem);
}


private void button4_Click(object sender, EventArgs e)
{
if (btnActivate.Text.IndexOf(Activate) != -1)
{
interceptor
= new MessageInterceptor(InterceptionAction.Notify);
interceptor.MessageReceived
+= new MessageInterceptorEventHandler(interceptor_MessageReceived);
btnActivate.Text
= Deactivate;
}


if (btnActivate.Text.IndexOf(Deactivate) != -1)
{
interceptor.Dispose();
interceptor
= null;
btnActivate.Text
= Activate;
}

interceptor_MessageReceived((
object)sender ,( MessageInterceptorEventArgs )e );
}




void interceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
SmsMessage sms
= (SmsMessage)e.Message;
string strFrom = sms.From.Address;
string strMessageText = sms.Body.Trim().ToLower();
bool bGotCommand = false;
string strReplyMessage = “”;

switch (strMessageText)
{
case getunreadsms:
strReplyMessage
= Unread SMS: +SystemState.MessagingSmsUnread;
bGotCommand
= true;
break;

case getunreademail:
strReplyMessage
= Unread Email: +SystemState.MessagingTotalEmailUnread;
bGotCommand
= true;
break;

case getunreadmms:
strReplyMessage
= Unread MMS: +SystemState.MessagingMmsUnread;
bGotCommand
= true;
break;
}


if (bGotCommand == true)
{
SmsMessage replySMS
= new SmsMessage();
replySMS.To.Add(
new Recipient(strFrom));
replySMS.Body
= strReplyMessage;
replySMS.Send();
}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值