3

我想以編程方式在BlackBerry中發送短信。如何在黑莓中以編程方式發送短信

請給我建議,如果您有任何想法..

我讀的地方,我需要sendind SMS服務器端以及客戶端代碼。它是真的嗎?對於從1設備發送消息到另一個設備或從模擬器發送到設備,我是否真的需要服務器端以及客戶端代碼?請指導me..Thanks提前..

我發現這個代碼某處客戶端,但我沒有得到output..Please幫助我..

private void sendSMS(String phone, String message) throws RuntimeException, ServicesManagerException, IOException 
    { 
     // TODO Auto-generated method stub 

     System.out.println("in send sms function"); 
     MessageConnection conn = 
      (MessageConnection)Connector.open("sms://+919099087960"); 
     BinaryMessage msgOut = (BinaryMessage) conn.newMessage(MessageConnection.BINARY_MESSAGE); 
     msgOut.setPayloadData("my binary payload".getBytes("UTF-8")); 
     conn.send(msgOut); 

    } 
+0

在我的代碼中,我得到RunTime異常。請幫助我..謝謝,, .. –

+0

@ Riddhi-我有同樣的問題...我可以運行應用程序來完成,但我沒有看到我的消息在BlackBerry模擬器的'消息'文件夾!你能幫我解決嗎? –

回答

5

你不需要任何服務器端代碼。檢查下面的代碼。

static String msg="hai"; 
try { 
    new Thread() { 
     public void run() { 
      if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) { 
       DatagramConnection dc = null; 
       try { 
        dc = (DatagramConnection) Connector.open("sms://+919099087960"); 
        byte[] data = msg.getBytes(); 
        Datagram dg = dc.newDatagram(dc.getMaximumLength()); 
        dg.setData(data, 0, data.length); 
        dc.send(dg); 
        UiApplication.getUiApplication().invokeLater(new Runnable() { 
         public void run() { 
          try { 
           System.out.println("Message Sent Successfully : Datagram"); 
           Dialog.alert("Message Sent Successfully"); 
          } catch (Exception e) { 
           System.out.println("Exception : " + e.toString()); 
           e.printStackTrace(); 
          } 
         } 
        }); 
       } catch (Exception e) { 
        System.out.println("Exception : " + e.toString()); 
        e.printStackTrace(); 
       } finally { 
        try { 
         dc.close(); 
         dc = null; 
        } catch (IOException e) { 
         System.out.println("Exception : " + e.toString()); 
         e.printStackTrace(); 
        } 
       } 
      } else { 
       MessageConnection conn = null; 
       try { 
        conn = (MessageConnection) Connector.open("sms://+919099087960"); 
        //generate a new text message 
        TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); 
        //set the message text and the address 
        tmsg.setAddress("sms://+919099087960"); 
        tmsg.setPayloadText(msg); 
        //finally send our message 
        conn.send(tmsg); 
        UiApplication.getUiApplication().invokeLater(new Runnable() { 
         public void run() { 
          try { 
           System.out.println("Message Sent Successfully : TextMessage"); 
           Dialog.alert("Message Sent Successfully : TextMessage"); 
          } catch (Exception e) { 
           System.out.println("Exception : " + e.toString()); 
           e.printStackTrace(); 
          } 
         } 
        }); 
       } catch (Exception e) { 
        System.out.println("Exception : " + e.toString()); 
        e.printStackTrace(); 
       } finally { 
        try { 
         conn.close(); 
         conn = null; 
        } catch (IOException e) { 
         System.out.println("Exception : " + e.toString()); 
         e.printStackTrace(); 
        } 
       } 
      } 
     } 
    }.start(); 
} catch (Exception e) { 
    System.out.println("Exception : " + e.toString()); 
    e.printStackTrace(); 
} 
+1

無法讀取的代碼 –

+0

@ Signare-我有一個同樣的問題...我可以運行應用程序來完成(我得到「Message Sent Successfully:TextMessage」的對話框),但我沒有在'Messages'文件夾中看到我的消息黑莓模擬器!你能幫我解決嗎? –

相關問題