2012-09-05 42 views
1

我正在开发一个适用于无线消息API(WMA)的j2me中的应用程序。该应用程序的任务是发送和2移动phone.When我运行在NetBeans模拟器,所以它工作正常,但在应用程序之间发送和接收短信,当我在诺基亚运行5200手机,我给手机这个异常:j2me中的SecurityException发送/接收SMS的WMA应用程序

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

我觉得现在的问题是,应用程序无法打开森迪连接ng或接收SMS,但我不知道为什么,因为我在模拟器中没有问题。

回答

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; 
} 

更新评论

关于安全异常后,发送一个简单的短信如下代码:或许手机只接受来自制造商和/或电信运营商/运营商的签名。在不同的手机上试用此签名版本。

+0

我试试这个代码,但我也有这个代码too.i几乎相信问题是从打开连接线,但我不知道为什么有这个该死的问题 – CoderInNetwork

+0

你的应用程序签名?如果你得到SecurityException,那么这可能是问题。 –

+0

是的,我从这里签署了申请:www.j2start.com/p/sign-your-midlet.html ...我真的搜查整个网络,但我没有发现任何有用的东西。你有任何想法亲? – CoderInNetwork

相关问题