【问题标题】:SecurityException in j2me WMA application for sending/receiving SMS用于发送/接收 SMS 的 j2me WMA 应用程序中的 SecurityException
【发布时间】:2012-09-05 16:49:13
【问题描述】:

我正在 j2me 中开发一个与无线消息 API (WMA) 配合使用的应用程序。应用程序任务是在两部手机之间发送和接收短信。当我在 NetBeans 模拟器中运行该应用程序时,它工作正常,但是当我在诺基亚 5200 手机上运行它时,我在手机上给出了这个异常:

Security java/lang/SecurituException Not allowed to open connection

我的应用程序的 JAD 文件是:

MIDlet-1: Midlet, , hello.Midlet
MIDlet-Jar-Size: 36375
MIDlet-Jar-URL: SinaNetwork.jar
MIDlet-Name: SinaNetwork
MIDlet-Permissions: javax.microedition.io.Connector.sms, javax.wireless.messaging.sms.receive, javax.wireless.messaging.sms.send
MIDlet-Vendor: Vendor
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0

应用程序代码也是:

Thread receive=new Thread(new Runnable() {
               MessageConnection ms;
            public void run() {
         //       System.out.print("*****************SALAM*******");

                    try {

                        ms= (MessageConnection) Connector.open("sms://:"+7000);
          //              System.out.println("Zoor mizanam Receive konam");
                        Date zaman=new Date();
                        long zamanTemp=zaman.getTime();

                        TextMessage tempmes=(TextMessage) ms.receive();
               //         System.out.print("SMS receive: "+tempmes.getPayloadText());
                        Midlet.messageReceived=true;
                        Midlet.ReceivedThatWeDontKnowIsRandom=tempmes.getPayloadText();
                    }
                    catch(SecurityException eds)
                    {
                        eds.printStackTrace();
                     //   System.out.print("");
                    }
                    catch (IOException ex) {
                        ex.printStackTrace();
                    }




            }
        });
         receive.start();

        Thread sendmesThread=new Thread(new Runnable() {

            public void run() {
                 try {

            MessageConnection mc=(MessageConnection) Connector.open("sms://"+Midlet.smsPhoneNumber+":"+5000); 

            TextMessage tm=(TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);

      //      System.out.print("PNF : "+phoneNumberField.getString());
            tm.setPayloadText(rd+"-"+phoneNumberField.getString());
            mc.send(tm);
         //   System.out.print("message sent from client on port 5000");
            mc.close();

        } 

            catch (IOException ex) {

            ex.printStackTrace();
        }

            }
        });

        sendmesThread.start();

我认为问题是应用程序无法打开发送或接收短信的连接,但我不知道为什么,因为我在模拟器中没有问题。

【问题讨论】:

    标签: java-me sms netbeans-7 securityexception wma


    【解决方案1】:

    您的问题可能出在您尝试使用的端口:7000 和 5000。我相信您希望 SMS 跳过用户收件箱并仅由应用程序处理,对吗?

    在执行此操作之前,请确保您的应用可以从http://www.developer.nokia.com/Community/Wiki/How_to_send_text_SMS_in_Java_ME 发送带有以下代码的简单短信

    public boolean sendSms(String number, String message){
      boolean result = true;
      try {
        //sets address to send message
        String addr = "sms://"+number;
        // opens connection
        MessageConnection conn = (MessageConnection) Connector.open(addr);
        // prepares text message
        TextMessage msg =
        (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
        //set text
        msg.setPayloadText(message);
        // send message
        conn.send(msg);
        conn.close();
      } catch (SecurityException se) {
        // probably the user has not allowed to send sms
        // you may want to handle this differently
      result = false;
      } catch (Exception e) {
        result = false;
      }
      return result;
    }
    

    cmets 后更新

    关于安全例外:手机可能只接受来自制造商和/或电信运营商/运营商的签名。在不同的手机上试用此签名版本。

    【讨论】:

    • 我尝试了这段代码,但我也遇到了同样的问题。我几乎可以确定问题出在打开连接线,但我不知道为什么会出现这个该死的问题
    • 您的应用程序是否已签名?如果您收到 SecurityException,那么这可能是问题所在。
    • 是的,我从这里签署了申请:www.j2start.com/p/sign-your-midlet.html ...我真的搜索了整个网络,但我没有找到任何有帮助。亲爱的,你有什么想法吗?
    • 也许手机只接受来自制造商和/或电信运营商/运营商的签名。 :( 你也可以在不同的手机上试试这个签名版本吗?
    • 我尝试这样做。我会告诉你我会做什么。谢谢 :)
    猜你喜欢
    • 2010-09-13
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多