我使用GSMComm库发送和接收消息(桌面应用程序).发送代码非常有效..。问题是当收到消息时,在使用Android设备时无法读取消息,至少替换了4台三星设备,但是与GSM-3G设备完美地工作。
错误显示在下面的DecodedShortMessage message = messages[indexx];行,并带有错误消息“索引超出了数组的界限”/。
安卓不允许从手机内存读取消息,同时允许发送消息吗?
我尽我所能,但我忍不住.
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() + ")");
}
}引用已经尝试过
发布于 2015-06-06 04:41:41
是的,我从论坛上读到,android不允许用gsmcomm从手机内存中读取消息,您可以使用android客户端通过套接字将短信从android发送到pc,或者如果您有很多钱,可以使用androino,我看到一篇关于如何接收和发送sms的文章。
我有一个问题,就是如何从SmsDeliverPdu命令中获取发送者和接收者的号码,因为我需要发送方和接收方来验证短消息,或者如何获取电话的sim号码。
https://stackoverflow.com/questions/30382513
复制相似问题