private static int index;
private static FileOutputStream fs;
public static void smsBackup(Context context, String path, ProgressDialog pd) {
index=0;
File file = new File(path);
Cursor cursor = context.getContentResolver().query(Uri.parse("content://sms"),
new String[]{"address", "date", "type", "body"}, null, null, null);
pd.setMax(cursor.getCount());
try {
fs = new FileOutputStream(file);
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(fs, "utf-8");
serializer.startDocument("utf-8", true);
serializer.startTag(null,"smss");
while(cursor.moveToNext())
{
serializer.startTag(null,"sms");
serializer.startTag(null,"address");
serializer.text(cursor.getString(0));
serializer.endTag(null,"address");
serializer.startTag(null,"date");
serializer.text(cursor.getString(1));
serializer.endTag(null,"date");
serializer.startTag(null,"type");
serializer.text(cursor.getString(2));
serializer.endTag(null,"type");
serializer.startTag(null,"body");
serializer.text(cursor.getString(3));
serializer.endTag(null,"body");
serializer.endTag(null,"sms");
//设置进度条框
index++;
pd.setProgress(index);
}
serializer.endTag(null,"smss");
serializer.endDocument();
} catch (Exception e) {
e.printStackTrace();
}
finally {
if(cursor!=null&&fs!=null) {
cursor.close();
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
联系客服