您的位置:首页 > 其它

J2ME 发送彩信问题,请个位高手帮忙,长时间在线等待

2017-01-02 23:33 337 查看
开发环境介绍:

eclipse + wtk 

问题:

将程序按照到nokia 5233的手机上后,通过程序发送彩信,彩信内容包括,图片和一段文字,发送到sony 爱立信的手机上。

1.nokia手机的发件箱中,打开刚发送的彩信后,有文字没有图片

2.爱立信手机上收到信息后,没有图片只有文字

然后本人在爱立信的手机上装上了程序,然后发送给nokia,nokia收到了彩信,并且有图片和文字

代码片段如下:

public class SendMMS extends Thread {

private MessagePart[] _msgParts = null;

private String _appID = "com.nakia.nfc.sample.app";

private String _phoneNO = null;

private String _address = null;

private String _subject = null;

private CameraMIDlet c = null;

public SendMMS(CameraMIDlet c, MessagePart[] msgParts, String appID,

String phoneNO, String subject) {

this._msgParts = msgParts;

this._appID = appID;

this._phoneNO = phoneNO;

this._subject = subject;

this.c = c;

}

/*

 * 发送彩信

 */

public void run() {

MessageConnection mmsconn = null;

try {

_address = "mms://" + _phoneNO;

/** 打开连接 */

mmsconn = (MessageConnection) Connector.open(_address);

MultipartMessage mmmessage = (MultipartMessage) mmsconn

.newMessage(MessageConnection.MULTIPART_MESSAGE);

mmmessage.setAddress(_address);

String priority = "normal"; // "high", "normal" or "low"

mmmessage.setHeader("X-Mms-Priority", priority);

for (int i = 0; i < _msgParts.length; i++) {

mmmessage.addMessagePart(_msgParts[i]);

}

// 由于J2me彩信设置主题只有setSubject(String)一个方法,而其内部默认字符编码格式

// 为UTF-16,所以中文主题显示为乱码,故不显示主题

// byte[] subjectBytes = _subject.getBytes("UTF-8");

// String tempSubject = new String(subjectBytes, "UTF-8");

// mmmessage.setSubject(_subject);

mmsconn.send(mmmessage);

c.addText("成功发送彩信");

} catch (Exception e) {

e.printStackTrace();

c.addText("发送失败:" + e.getMessage());

} finally {

if (mmsconn != null) {

try {

mmsconn.close();

} catch (IOException ioe) {

ioe.printStackTrace();

}

}

}

}

}

public class MMSMessage {

private Vector parts = new Vector();

private int counter = 0;

/*

 * 获得添加完成后的彩信内容

 */

public MessagePart[] getParts() {

// parts 是一个Vector对象,它包括Mulitpart 消息

MessagePart[] partsArray = new MessagePart[parts.size()];

parts.copyInto(partsArray);

return partsArray;

}

/*

 * 添加文本部分到彩信

 */

public void addTextPart(String text, String mimeType, String encoding) {

MessagePart mpart = null;

byte[] contents = null;

try {

contents = text.getBytes(encoding);

mpart = new MessagePart(contents, 0, contents.length, mimeType,

"id" + counter, "contentLocation", encoding);

parts.addElement(mpart);

counter++;

} catch (Exception e) {

e.printStackTrace();

} finally {

mimeType = null;

encoding = null;

mpart = null;

contents = null;

}

}

/*

 * 添加图片部分到彩信

 */

public void addImagePart(byte[] raw, String mimeType) {

MessagePart mpart = null;

byte[] contents = null;

try {

// String mimeType = "image/jpeg";

InputStream in = new ByteArrayInputStream(raw);

contents = raw;

mpart = new MessagePart(in, mimeType,

"id" + counter, "image.jpg", null);

parts.addElement(mpart);

counter++;

} catch (Exception e) {

e.printStackTrace();

} finally {

mpart = null;

contents = null;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: