2012-09-27 45 views
-3

我正在開發一個移動應用程序,我需要能夠訪問在J2ME或LWUIT默認的短信服務,我只是說我要發送的消息,我怎樣才能把我的消息默認送我的手機的消息應用,並讓用戶選擇聯繫人,然後重新發送消息並給我的應用程序發送短信在J2ME

請我需要緊急幫助

回答

1

檢查下面的代碼:

public class SendSMS extends Thread { 

private String receiver; 
private String receivedMsg; 
private HomeScreen home; 
private boolean bool = false; 
private boolean notsent; 

public SendSMS(HomeScreen gen, String msg, String number) { 
    this.home = gen; 
    this.receiver = number; 
    this.receivedMsg = msg; 
} 

public void run() { 
    while (!bool) { 
     SendMessage(); 
    } 
} 

/** 
* Send the mesage using WMA api. 
*/ 
private void SendMessage() { 
    String s = "sms://" + receiver; 
    send(s); 
} 

private void send(String url) { 
    MessageConnection messageconnection = null; 
    try { 
     messageconnection = (MessageConnection) Connector.open(url); 
     TextMessage textmessage = (TextMessage) messageconnection.newMessage(MessageConnection.TEXT_MESSAGE); 
     textmessage.setAddress(url); 
     textmessage.setPayloadText(receivedMsg); 
     messageconnection.send(textmessage); 
    } catch (Exception throwable) { 
     notsent = true; 
     home.genericObject.setSmsStatus(false); 
     if (!home.isNokia()) { 
      new PopUp("Message not sent"); // not sent 
     } 
     bool = true; 
     try { 
      messageconnection.close(); 
     } catch (Exception e) { 
     } 
    } 

    if (messageconnection != null) { 
     try { 
      messageconnection.close(); 
      if (!notsent) { 
       home.genericObject.setSmsStatus(false); 
       if (!home.isNokia()) { 
        new PopUp("Message Sent"); // sent 
       } 
      } 
      bool = true; 
     } catch (Exception ie) { 
      ie.printStackTrace(); 
     } 
    } 
} 
+0

無想法爲什麼這被投票了,它甚至不完整。 – funkybro