日期:2014-05-20  浏览次数:20745 次

请问一下彩信中文的问题
为什么发送中文的时候,出现乱码的?content是GB2312编码.

boolean result = true;
  MessagePart mpart = null;
  String mimeType = "text/plain";
  String encoding = "GB2312";
  String mImageToSend="file://localhost/E:/mmsexample.jpg";
  byte[] contents = null;
  try {
  contents = content.getBytes(encoding);
  mpart = new MessagePart(contents, 0, contents.length, mimeType,
  "id" + Integer.toString(1), "contentLocation", encoding);
  } catch (Exception e) {
log("MMS " + e.toString());
  }

  String address = "mms://" + phoneNumber;
  MessageConnection mmsconn = null;
  if (mpart == null) {
  return false;
  }
  try {
FileConnection fc = (FileConnection)Connector.open(mImageToSend, Connector.READ);
log("Opened");
if(fc.exists())
{
log("existed");
}
else
{
log("not existed");
}
mmsconn = (MessageConnection) Connector.open(address);
  MultipartMessage mmmessage = (MultipartMessage) mmsconn
  .newMessage(MessageConnection.MULTIPART_MESSAGE);
  mmmessage.setAddress(address);
  InputStream is = fc.openInputStream();
  byte[] bImage = new byte[is.available()];
  // Tracer.outln("Opened2",t);
  is.read(bImage); //把图片变为byte数组
  // Tracer.outln("Opened3",t);
  //加载数据包
  mmmessage.addMessagePart(new MessagePart(bImage, 0, bImage.length,"image/png", "id2", "location", null));
  mmmessage.addMessagePart(mpart);
  mmmessage.setSubject("MMS Text");
  mmsconn.send(mmmessage);
  mmsconn.close();
  fc.close();
  } catch (Exception e) {
log("MMS " + e.toString());
  }

------解决方案--------------------
学习ING
------解决方案--------------------
改成utf8
------解决方案--------------------
没办法解决,LZ可以把中文用点阵像素图的方式表现出来,这是解决乱码的万能方案