详解微软 Nokia Lumia手机导出的短信如何导入到安卓手机中
最近换手机了,但是有个很坑爹的问题,那就是微软这货太与众不同了。
我先前使用的是wp的lumia手机,使用“传输我的数据”应用导入到sd卡后,短信备份文件居然是一个vmsg文件,找遍全网,没有看到一个现成的解决转换问题的方法。由此可见微软有多孤僻。。。
不过,还好我是程序猿,,攻城师,所以这个问题没有难倒我哦,现在是彻底解决了。
下面我详细说一下从前到后的所有过程
1. 首先要使用“传输我的数据”应用导出至sd卡,在应用中单击屏幕最下面的“...”就可以看到。
2.然后将sd卡的vmsg备份文件拷贝到电脑上
3.攻城师来了。。。
看代码:
总共有三个源代码:
代码中有个文件路径的字串,随自己的实际情况更改!!
(1)
-
import java.io.File;
-
import java.nio.ByteBuffer;
-
import java.nio.CharBuffer;
-
import java.nio.charset.Charset;
-
import java.util.HashMap;
-
import java.util.Map;
-
import java.util.Scanner;
-
-
public class ConvertMain {
-
-
public static void main(String[] args) {
-
StringBuilder convertedString = new StringBuilder();
-
Map<String, Integer> map = new HashMap<String, Integer>();
-
int count = 1;
-
try {
-
Scanner scanner = new Scanner(new File("e:\\sms.vmsg"));
-
StringBuilder builder = new StringBuilder();
-
String str = new String();
-
Msg msg = new Msg();
-
do {
-
str = scanner.nextLine();
-
if (str.equals("BEGIN:VMSG")) {
-
builder.append("sms,");
-
} else if (str.startsWith("TEL")) {
-
// 加入TEL
-
msg.setTel(str.substring(4));
-
if (!map.keySet().contains(str.substring(4))) {
-
map.put(str.substring(4), count++);
-
}
-
-
} else if (str.startsWith("X-BOX")) {
-
// 加入投送方式
-
if (str.endsWith("INBOX")) {
-
msg.setX_box(2);
-
} else if (str.endsWith("SENDBOX")) {
-
msg.setX_box(3);
-
}
-
} else if (str.startsWith("Date")) {
-
// 加入日期
-
msg.setDate(str.substring(5).replaceAll("/", "\\.")
-
.substring(0, 16));
-
} else if (str.startsWith("Subject")) {
-
// 加入内容
-
StringBuilder builder2 = new StringBuilder();
-
builder2.append(str.substring(48));
-
String str1 = scanner.nextLine();
-
while (!str1.startsWith("END")) {
-
builder2.append(str1);
-
str1 = scanner.nextLine();
-
}
-
String source = builder2.toString().replaceAll("==", "=");
-
byte[] array = getBytes(source.toCharArray());
-
msg.setContent(QuotedPrintable.decode(array, "UTF-8")
-
.replaceAll("\\s+", ""));
-
}
-
if (msg.getContent() != null && msg.getDate() != null
-
&& msg.getTel() != null && msg.getX_box() != 0) {
-
if (msg.getX_box() == 2) {
-
// deliver + ",count"
-
builder.append("deliver, " + msg.getTel() + ",,,"
-
+ msg.getDate() + "," + map.get(msg.getTel())
-
+ "," + msg.getContent() + "\r");
-
} else if ((msg.getX_box() == 3)) {
-
// send
-
builder.append("submit,, " + msg.getTel() + ",,"
-
+ msg.getDate() + "," + map.get(msg.getTel())
-
+ "," + msg.getContent() + "\r");
-
}
-
convertedString.append(builder.toString());
-
msg = new Msg();
-
builder = new StringBuilder();
-
}
-
} while (str != "" && str != null);
-
-
} catch (Exception e) {
-
}
-
System.out.println(convertedString);
-
}
-
-
private static byte[] getBytes(char[] chars) {
-
Charset cs = Charset.forName("UTF-8");
-
CharBuffer cb = CharBuffer.allocate(chars.length);
-
cb.put(chars);
-
cb.flip();
-
ByteBuffer bb = cs.encode(cb);
-
-
return bb.array();
-
-
}
-
/*
-
// byte转char
-
private static char[] getChars(byte[] bytes) {
-
Charset cs = Charset.forName("UTF-8");
-
ByteBuffer bb = ByteBuffer.allocate(bytes.length);
-
bb.put(bytes);
-
bb.flip();
-
CharBuffer cb = cs.decode(bb);
-
-
return cb.array();
-
}*/
-
}
(2)
-
import java.io.UnsupportedEncodingException;
-
-
-
public class QuotedPrintable {
-
-
private final static byte TAB = 0x09; // /t
-
private final static byte LF = 0x0A; // /n
-
private final static byte CR = 0x0D; // /r
-
//private final static byte SPACE = 0x20; // ' '
-
private final static byte EQUALS = 0x3D; // '='
-
-
private final static byte LIT_START = 0x21;
-
private final static byte LIT_END = 0x7e;
-
-
private final static int MAX_LINE_LENGTH = 76;
-
-
private static int mCurrentLineLength = 0;
-
-
/**
-
* A method to decode quoted printable encoded data.
-
* It overrides the same input byte array to save memory. Can be done
-
* because the result is surely smaller than the input.
-
*
-
* @param qp
-
* a byte array to decode.
-
* @return the length of the decoded array.
-
*/
-
public static int decode(byte [] qp) {
-
int qplen = qp.length;
-
int retlen = 0;
-
-
for (int i=0; i < qplen; i++) {
-
// Handle encoded chars
-
if (qp[i] == '=') {
-
if (qplen - i > 2) {
-
// The sequence can be complete, check it
-
if (qp[i+1] == CR && qp[i+2] == LF) {
-
// soft line break, ignore it
-
i += 2;
-
continue;
-
-
} else if (isHexDigit(qp[i+1]) && isHexDigit(qp[i+2]) ) {
-
// convert the number into an integer, taking
-
// the ascii digits stored in the array.
-
qp[retlen++]=(byte)(getHexValue(qp[i+1])*16
-
+ getHexValue(qp[i+2]));
-
-
i += 2;
-
continue;
-
-
} else {
-
System.out.println("decode: Invalid sequence = " + qp[i+1] + qp[i+2]);
-
}
-
}
-
// In all wrong cases leave the original bytes
-
// (see RFC 2045). They can be incomplete sequence,
-
// or a '=' followed by non hex digit.
-
}
-
-
// RFC 2045 says to exclude control characters mistakenly
-
// present (unencoded) in the encoded stream.
-
// As an exception, we keep unencoded tabs (0x09)
-
if( (qp[i] >= 0x20 && qp[i] <= 0x7f) ||
-
qp[i] == TAB || qp[i] == CR || qp[i] == LF) {
-
qp[retlen++] = qp[i];
-
}
-
}
-
-
return retlen;
-
}
-
-
private static boolean isHexDigit(byte b) {
-
return ( (b>=0x30 && b<=0x39) || (b>=0x41&&b<=0x46) );
-
}
-
-
private static byte getHexValue(byte b) {
-
return (byte)Character.digit((char)b, 16);
-
}
-
-
/**
-
*
-
* @param qp Byte array to decode
-
* @param enc The character encoding of the returned string
-
* @return The decoded string.
-
*/
-
public static String decode(byte[] qp, String enc) {
-
int len=decode(qp);
-
try {
-
return new String(qp, 0, len, enc);
-
} catch (UnsupportedEncodingException e) {
-
return new String(qp, 0, len);
-
}
-
}
-
-
/**
-
* A method to encode data in quoted printable
-
*
-
* @param content
-
* The string to be encoded
-
* @param enc
-
* The character encoding of the content string
-
* @return The encoded string. If the content is null, return null.
-
*/
-
public static String encode(String content, String enc) {
-
if (content == null)
-
return null;
-
-
byte[] str = null;
-
try {
-
str = content.getBytes(enc);
-
} catch (UnsupportedEncodingException e) {
-
str = content.getBytes();
-
}
-
return encode(str);
-
}
-
/**
-
* A method to encode data in quoted printable
-
*
-
* @param content
-
* The byte array of the string to be encoded
-
* @return The encoded string. If the content is null, return null.
-
*/
-
public static String encode(byte[] content) {
-
if (content == null
阅读(1209) | 评论(0) | 转发(0) |