【问题标题】:Why Unable to read Message From "Android Device" Using GSMComm Library ,C#为什么无法使用 GSMComm 库,C# 从“Android 设备”读取消息
【发布时间】: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() + ")");
            }
        }

参考文献已经尝试过

  1. Official Site
  2. Code Project Bluck SMS Sender
  3. Send Receive SMS

【问题讨论】:

    标签: c# android c#-4.0 sms c#-3.0


    【解决方案1】:

    是的,因为我从论坛上读到,android 不允许使用 gsmcomm 从手机内存中读取消息,您可以使用 android 客户端通过套接字将短信从 android 发送到 pc,或者如果您有很多钱,您可以使用 androino i请参阅有关如何接收和发送短信的文章。

    我有一个关于如何从 SmsDeliverPdu 对象中获取发送方和接收方号码的问题,因为我需要发送方和接收方验证短信或如何获取手机的 sim 号码

    【讨论】:

    • SmsDeliverPdu 数据 = (SmsDeliverPdu)pdu; MessageBox.Show(data.OriginatingAddress.ToString());
    • 感谢回复,但只有发件人号码发送短信,但收到短信的 SIM 卡号码我不知道我是否错了,但我们应该从 comm.GetSubscriberNumbers( );并且此功能不适用于我的模拟人生,因为不支持网络提供商
    猜你喜欢
    • 2012-05-03
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 2010-12-29
    相关资源
    最近更新 更多