Question

I am developing an Application in j2me that works with Wireless Messaging API (WMA). The application mission is sending and receiving SMS between 2 mobile phone.When i run the app in NetBeans emulator it works fine but when i run it on Nokia 5200 phone i give this exception on mobile phone :

Security java/lang/SecurituException Not allowed to open connection

The JAD file of my app is :

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

The Application code is also :

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();

I think that the problem is that the application can't open the connection for sending or receiving SMS but I don't know why because I have no problem in emulator.

Was it helpful?

Solution

Your problem might reside on the ports you are trying to use: 7000 and 5000. I believe you want the SMS to skip the users inbox and be treated only by the application, right?

Before doing it, please, make sure your app can send a simple SMS with below code from 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;
}

Update after comments

About the Security Exception: maybe the phone only accepts signatures from the manufacturer and/or telecom operator/carrier. Try this signed version on different phones.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top