【发布时间】:2015-05-21 19:17:22
【问题描述】:
我正在使用 GSMComm Library 发送和接收消息(桌面应用程序)... 发送代码完美.. 问题是当收到一条消息时,我 在使用 Android 设备时无法阅读消息,更换了至少 4 台三星设备,但是它与 GSM-3G 设备完美配合强>
错误出现在以下行
DecodedShortMessage message = messages[indexx]; 带有错误消息“索引超出了数组的范围。”/
Android是否不允许从手机内存读取消息而允许发送消息?
我尽我所能,但无法帮助自己..
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e)
{
try
{
IMessageIndicationObject obj = e.IndicationObject;
if (obj is MemoryLocation)
{
MemoryLocation loc = (MemoryLocation)obj;
string storage=loc.Storage;
int indexx = loc.Index;
DecodedShortMessage[] messages = comm.ReadMessages(PhoneMessageStatus.All, loc.Storage);
//Error Shows up in next Line ,
//Exception Message is "Index was outside the bounds of the array."
DecodedShortMessage message = messages[indexx];
SmsPdu pdu = message.Data;
if (pdu is SmsDeliverPdu)
{
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
MessageBox.Show(data.OriginatingAddress.ToString() + data.UserDataText.ToString());
}
return;
}
MessageBox.Show("Error: Unknown notification object!");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message + " (" + ex.GetType().ToString() + ")");
}
}
参考文献已经尝试过
【问题讨论】:
标签: c# android c#-4.0 sms c#-3.0