Blackberry sends SMS messages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.