下边的代码说明了如何在J2ME程序中发送二进制短消息(图像、声音文件等)
void sendSMS(byte data[]) {
try {
String destAddress = "sms://9590528892:5001";
MessageConnection smsConnection =
(MessageConnection)Connector.open(destAddress);
//创建二进制消息
BinaryMessage binaryMSG = (BinaryMessage)smsConnection.newMessage(
MessageConnection.BINARY_MESSAGE);
//设置目标地址
binaryMSG.setAddress(destAddress);
//添加数据
binaryMSG.setPayloadData(data);
//发送消息
smsConnection.send(binaryMSG);
smsConnection.close();
} catch(Exception e) {
System.out.println("e="+e);
frm.append("e="+e);
}
}
本文介绍了一种在J2ME平台下发送包含图像或声音文件等二进制数据短信的方法。通过示例代码展示了如何使用MessageConnection创建并发送BinaryMessage,包括设置目标地址、添加数据和发送消息的具体步骤。

被折叠的 条评论
为什么被折叠?



