Package com. peidw. SMS;
Import javax. microedition. Io. connector;
Import javax. Wireless. messaging. messageconnection;
Import javax. Wireless. messaging. textmessage;
/**
*
*
*
*/
Import java. Io. ioexception;
Import javax. microedition. Io. connector;
Import javax. Wireless. messaging. messageconnection;
Public class sendsms {
Public static void sendsms (string phonenumber, string messagecontext ){
Try {
Messageconnection MC = (messageconnection) connector
. Open ("SMS: //" + phonenumber );
Sender sender = new sender (MC );
Sender. Send (null, messagecontext );
} Catch (ioexception e ){
E. printstacktrace ();
System. out. println ("************************ exception =" + E. tostring ());
}
}
}
-------------------
Package com. peidw. SMS;
Import javax. Wireless. messaging. messageconnection;
Import javax. Wireless. messaging. textmessage;
Public final class sender extends thread {
Private messageconnection _ MC;
Private string _ address;
Private string _ message;
Public sender (messageconnection MC ){
This. _ MC = MC;
Start ();
}
Public synchronized void send (string ADDR, string MSG ){
_ Address = ADDR;
_ Message = MSG;
Notify ();
}
Public synchronized void run (){
While (true ){
// If no client to deal, wait until one connects
If (_ message = NULL ){
Try {
Wait ();
} Catch (interruptedexception e ){
}
}
Try {
Textmessage MSG;
// Are we a sender thread for the client? If so then there's
// No address Parameter
If (_ address = NULL ){
MSG = (textmessage) _ MC
. Newmessage (messageconnection. text_message );
} Else {
MSG = (textmessage) _ MC. newmessage (
Messageconnection. text_message, _ address );
}
MSG. setpayloadtext (_ message );
_ MC. Send (MSG );
} Catch (exception IOE ){
IOE. printstacktrace ();
}
// Completed client handling, return handler to pool and
// Mark for wait
_ Message = NULL;
}
}
}
Use messageconnection to send messages.
For email information
Call session. gettransport () and store the returned object in a variable of Type
Transport. The transport object represents the messaging transport protocol.
Transport TRANS = session. gettransport ();
Call trans. Send (Message ).
Try {
Trans. Send (MSG );
} Catch (messagingexception e) {system. Out. println (E. getmessage ());
}
This method is used to send messages.
Official Reference documents:
Http://docs.blackberry.com/en/developers/deliverables/15665/Notify_app_sms_msg_about_to_be_sent_565448_11.jsp