当前位置: 首页 > 知识库问答 >
问题:

SMSLib不接收短信[java edition]

林亦
2023-03-14

我试图使用我的手机作为GSM调制解调器。我使用SMSLib发送和接收短信用这个调制解调器。问题是,当我的手机(GSM调制解调器)收到短信时,我没有用SMSL通知ib.but代码整体是好的,例如当GSM调制解调器收到呼叫时通知我。我的代码没有任何错误,因为我只使用SMSLib示例代码接收消息。SMSLib示例代码是:

public class TestSinaRec
{
    public void doIt() throws Exception
    {
        // Define a list which will hold the read messages.
        List<InboundMessage> msgList;
        // Create the notification callback method for inbound & status report
        // messages.
        InboundNotification inboundNotification = new InboundNotification();
        // Create the notification callback method for inbound voice calls.
        CallNotification callNotification = new CallNotification();
        //Create the notification callback method for gateway statuses.
        GatewayStatusNotification statusNotification = new GatewayStatusNotification();
        OrphanedMessageNotification orphanedMessageNotification = new OrphanedMessageNotification();
        try
        {
            System.out.println("Example: Read messages from a serial gsm modem.");
            System.out.println(Library.getLibraryDescription());
            System.out.println("Version: " + Library.getLibraryVersion());
            // Create the Gateway representing the serial GSM modem.
            SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 115200, "Nokia", " 6303i");
            // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
            gateway.setProtocol(Protocols.PDU);
            // Do we want the Gateway to be used for Inbound messages?
            gateway.setInbound(true);
            // Do we want the Gateway to be used for Outbound messages?
            gateway.setOutbound(true);
            // Let SMSLib know which is the SIM PIN.
            gateway.setSimPin("0444");
            // Set up the notification methods.
            Service.getInstance().setInboundMessageNotification(inboundNotification);
            Service.getInstance().setCallNotification(callNotification);
            Service.getInstance().setGatewayStatusNotification(statusNotification);
            Service.getInstance().setOrphanedMessageNotification(orphanedMessageNotification);
            // Add the Gateway to the Service object.
            Service.getInstance().addGateway(gateway);
            // Similarly, you may define as many Gateway objects, representing
            // various GSM modems, add them in the Service object and control all of them.
            // Start! (i.e. connect to all defined Gateways)
            Service.getInstance().startService();
            // Printout some general information about the modem.
            System.out.println();
            System.out.println("Modem Information:");
            System.out.println("  Manufacturer: " + gateway.getManufacturer());
            System.out.println("  Model: " + gateway.getModel());
            System.out.println("  Serial No: " + gateway.getSerialNo());
            System.out.println("  SIM IMSI: " + gateway.getImsi());
            System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
            System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
            System.out.println();
            // In case you work with encrypted messages, its a good time to declare your keys.
            // Create a new AES Key with a known key value. 
            // Register it in KeyManager in order to keep it active. SMSLib will then automatically
            // encrypt / decrypt all messages send to / received from this number.
            //Service.getInstance().getKeyManager().registerKey("+306948494037", new AESKey(new SecretKeySpec("0011223344556677".getBytes(), "AES")));
            // Read Messages. The reading is done via the Service object and
            // affects all Gateway objects defined. This can also be more directed to a specific
            // Gateway - look the JavaDocs for information on the Service method calls.
            msgList = new ArrayList<InboundMessage>();
            Service.getInstance().readMessages(msgList, MessageClasses.ALL);
            for (InboundMessage msg : msgList)
                System.out.println(msg);
            // Sleep now. Emulate real world situation and give a chance to the notifications
            // methods to be called in the event of message or voice call reception.
            System.out.println("Now Sleeping - Hit <enter> to stop service.");
            System.in.read();
            System.in.read();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            Service.getInstance().stopService();
        }
    }

    public class InboundNotification implements IInboundMessageNotification
    {
        public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg)
        {
            if (msgType == MessageTypes.INBOUND) System.out.println(">>> New Inbound message detected from Gateway: " + gateway.getGatewayId());
            else if (msgType == MessageTypes.STATUSREPORT) System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gateway.getGatewayId());
            System.out.println(msg);
        }
    }

    public class CallNotification implements ICallNotification
    {
        public void process(AGateway gateway, String callerId)
        {
            System.out.println(">>> New call detected from Gateway: " + gateway.getGatewayId() + " : " + callerId);
        }
    }

    public class GatewayStatusNotification implements IGatewayStatusNotification
    {
        public void process(AGateway gateway, GatewayStatuses oldStatus, GatewayStatuses newStatus)
        {
            System.out.println(">>> Gateway Status change for " + gateway.getGatewayId() + ", OLD: " + oldStatus + " -> NEW: " + newStatus);
        }
    }

    public class OrphanedMessageNotification implements IOrphanedMessageNotification
    {
        public boolean process(AGateway gateway, InboundMessage msg)
        {
            System.out.println(">>> Orphaned message part detected from " + gateway.getGatewayId());
            System.out.println(msg);
            // Since we are just testing, return FALSE and keep the orphaned message part.
            return false;
        }
    }

    public static void main(String args[])
    {
        TestSinaRec app = new TestSinaRec();
        try
        {
            app.doIt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

程序输出例如:

modem.com4的网关状态更改,旧:停止-

调制解调器信息:制造商:诺基亚型号:诺基亚6303i经典序列号:355382041051833 SIM IMSI:*屏蔽**信号电平:-57 dBm电池电平:91%

现在睡觉-点击停止服务。从网关检测到新呼叫:调制解调器。com4:989111007483从网关:调制解调器检测到新呼叫。com4:989111007483

当我搜索这个问题时,我发现:

此方法的正确操作取决于未经请求的调制解调器指示和CNMI命令的正确操作。如果您看到使用回调方法接收消息失败,可能调制解调器指示没有正确设置。

所以我用诺基亚6303i更换了我的手机(我的GSM调制解调器),而不是我第一次使用的诺基亚5200,但问题没有解决。所以现在我真的不知道选择另一部手机能解决这个问题吗?!或者我应该寻找更好、更合理的解决方案。

谢谢你对解决这个问题的任何帮助。

共有3个答案

冯敏达
2023-03-14

问题出在我的手机上。SmSlib不适用于各种手机(包括智能手机、大多数诺基亚手机等)的短信监听。)。我没有检查,但如果你使用专用的GSM调制解调器(如华为GSM调制解调器),这个问题可能会得到解决

阴高刚
2023-03-14


我的GT-I9000有问题,他收到了入站警报,但无法获取正确的sms对象,我认为这是存储位置的问题,我尝试了我的一个朋友的另一部手机(三星GT-S5670 Android),他在SIM卡内存中存储了一些消息,smslibrary收到通知,ReadMessages类记录了所有消息。

所以我认为你需要找到某种方法来改变ReadMessages上的存储位置。java或找到一款兼容手机,可以将短信存储到Sim卡而不是手机存储器中。

希望这有帮助。

鲜于光辉
2023-03-14

我唯一能想到的是,您正在启动Service,然后将SMS发送到调制解调器。因此,这一行不会被称为:Service.getInstance(). readMessages(msgList,MessageClass. ALL);。但是,您仍然应该收到新消息已到达调制解调器的通知。

尝试实现InundNotify,当它检测到调制解调器上的任何新消息时获取消息。通过重写过程()方法来做到这一点。

然而,这也可能是因为您实际上正在按

有时它就是这么愚蠢的事情。让我知道它是否有任何帮助,或者我是否完全误解了你的问题。我自己正在开发一个多调制解调器网关,所以我很乐意帮忙。

 类似资料:
  • 问题内容: 我尝试在我的应用中收到短信,并且确定问题出在我的AndroidManifest.xml文件中 我的SmsReceive.java就是这样 我确定我的问题出在manifest.xml中,因为 什么都不显示 我该怎么办 ? 编辑:正如我们的朋友所说的,我曾经用过 在我的函数中,但LogCat中什么也不会显示,所以我断然确定我的问题出在我的AndroidManifest.xml注意:我在HT

  • 本文向大家介绍Android BroadcastReceiver接收收到短信的广播,包括了Android BroadcastReceiver接收收到短信的广播的使用技巧和注意事项,需要的朋友参考一下 一、知识介绍   1、broadcastReceiver是广播接受者,四大组件之一。   2、Android中内置了很多系统级别的广播,可以在应用程序中得到各种系统的状态信息。   3、使用场景:  

  • 嗨,我试图捕捉短信内容和使用我的应用程序,所以我做了一个广播接收器与许可和清单,但当设备接收短信,我的代码不运行,这意味着广播接收器不发射。我也查了这里里里外外的很多文章,有一些: Android短信接收结果到主要活动短信接收不工作 我还尝试在活动onCreate()中动态注册接收器,但没有任何变化 有人知道问题出在哪里吗?它应该只是庆祝一个消息被累犯,这样我就可以继续工作,但接收器似乎甚至没有发

  • 本文向大家介绍Android接收和发送短信处理,包括了Android接收和发送短信处理的使用技巧和注意事项,需要的朋友参考一下 关于短信接收处理方面,当前已经有一些app做的比较好了,比如发给手机发验证码验证的问题,很多app在手机接收到验证码后,不需要输入,就直接可以跳过验证界面,这就是用到了对接收到的短信的处理。至于短信的发送,也没什么好说的了。在此也只是附上一个小实例。 效果图: MainA

  • 我可以用//div[@ class = ' entry-content ']/p获取以“今天的项目”开头的文本,还可以用//div[@ class = ' entry-content ']//a[@ title]//*获取下一个标签以及它后面的所有文本。然而,正如您所看到的,在“/span”之后仍然有一些文本。然而,我试过的方法都不管用。我试过查看元素的子元素,试过//div[@ class =

  • 我希望我的Java应用程序在不使用任何额外硬件设备的情况下发送和接收短信,而且它必须是免费的。 我进行了搜索,但我只找到了标题,我找到了一些类似SMSLib的东西,但另一方面,我没有找到学习这些的教程或书籍。 我还发现了SMSLib代码,但不明白: 发送消息/短信代码 阅读信息/短信代码