Saturday, February 21, 2009

How To - Programmatically send a PIN message


The code sample below explains how to programmatically send a personal identification number (PIN) message from one BlackBerry device to another device that has PIN 20000000. This code sample uses the net.rim.blackberry.api.mail package.

Store store = Session.getDefaultInstance().getStore();
//retrieve the sent folder
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
//create a new message and store it in the sent folder
Message msg = new Message(sentfolder);
PINAddress recipients[] = new PINAddress[1];
try{
//create a pin address with destination address of 20000000
recipients[0]= new PINAddress("20000000", "Robert");
}
catch (AddressException ae)
{
System.err.println(ae);
}
try{
//add the recipient list to the message
msg.addRecipients(Message.RecipientType.TO, recipients);
//set a subject for the message
msg.setSubject("Test pin message");
//sets the body of the message
msg.setContent("This is a test pin message from my
BlackBerry Wireless Handheld");
//send the message
Transport.send(msg);
}
catch (MessagingException me)
{
System.err.println(me);
}

Works on :

  • BlackBerry wireless devices based on Java
  • BlackBerry Device Software 4.0 and higher

Note: This is not supported in BlackBerry Device Software 3.8 and earlier, and cannot be reproduced on the device simulators.

2 comments:

  1. I have tried this code on OS 5 and it works.
    But it doesnt work on OS6, any thought?

    ReplyDelete
  2. how i could use this code

    ReplyDelete

Place your comments here...