編輯:系統備份
短信的實體bean
package com.examp.backsms.domain; public class SmsInfo { private String address; private String date; private String type; private String body; public SmsInfo() { } public SmsInfo(String address, String date, String type, String body) { this.address = address; this.date = date; this.type = type; this.body = body; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } @Override public String toString() { return "SmsInfo [address=" + address + ", date=" + date + ", type=" + type + ", body=" + body + "]"; } }
package com.examp.backsms; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.view.View; import com.examp.backsms.domain.SmsInfo; import com.examp.backsms.util.SmsUtils; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void backSms(View view) { // 創建被叫主機名 Uri uri = Uri.parse("content://sms/"); // 獲取內容解析器 ContentResolver resolver = getContentResolver(); // 執行查詢,得到結果集 Cursor cursor = resolver.query(uri, new String[] { "address", "date", "type", "body" }, null, null, null); //創建短信的集合 Listinfos = new ArrayList (); //逐一添加到集合 while (cursor.moveToNext()) { SmsInfo info = new SmsInfo(); info.setAddress(cursor.getString(cursor.getColumnIndex("address"))); info.setBody(cursor.getString(cursor.getColumnIndex("body"))); info.setDate(cursor.getString(cursor.getColumnIndex("date"))); info.setType(cursor.getString(cursor.getColumnIndex("type"))); infos.add(info); } //通過工具類調用備份的業務 //將集合|本活動的上下文傳入 SmsUtils.backupSms(infos, this); cursor.close(); } }
工具類
package com.examp.backsms.util; import java.io.File; import java.io.FileOutputStream; import java.util.List; import org.xmlpull.v1.XmlSerializer; import android.content.Context; import android.os.Environment; import android.util.Xml; import android.widget.Toast; import com.examp.backsms.domain.SmsInfo; public class SmsUtils { public static void backupSms(ListsmsInfos, Context context) { try { // 創建XML序列化器 XmlSerializer serializer = Xml.newSerializer(); File file = new File(Environment.getExternalStorageDirectory(), "backupSms.xml"); FileOutputStream os = new FileOutputStream(file); // 初始化xml序列化器,指定xml數據寫入到那個文件,並且制定文件的編碼方式 serializer.setOutput(os, "utf-8"); // 設置,及是否是獨立的xml文件 serializer.startDocument("utf-8", true); // 相當於 serializer.startTag(null, "smss"); for (SmsInfo info : smsInfos) { serializer.startTag(null, "sms"); serializer.startTag(null, "body"); serializer.text(info.getBody()); serializer.endTag(null, "body"); serializer.startTag(null, "type"); serializer.text(info.getType() + ""); serializer.endTag(null, "type"); serializer.startTag(null, "address"); serializer.text(info.getAddress()); serializer.endTag(null, "address"); serializer.startTag(null, "date"); serializer.text(info.getDate() + ""); serializer.endTag(null, "date"); serializer.endTag(null, "sms"); } serializer.endTag(null, "smss"); serializer.endDocument(); os.close(); Toast.makeText( context, "備份短信成功,備份儲存路徑為:" + Environment.getExternalStorageDirectory() + "backSms.xml", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(context, "備份短信息失敗!!", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } }
0019短信備份 Settings 備份短信
注意 刷機有風險 刷機和ROOT帶來的一切問題與本人無關, 首先是安卓機器名詞解釋(適用新手):只需要刷機教程的可以直接下拉觀找到藍色字體部分看刷機教程即可,有卡刷/線刷
如何備份微信聊天記錄?請打開微信 -> “我” -> 設置 -> 通用 -> 聊天記錄遷移(以前叫做&ldq
由於聯想樂檬X3版本有好幾個,所以許多的樂檬X3機友在刷機時由不看型號刷機,不是把雙4G固件刷到了全網通上,就是把全網通固件刷到了雙4G上,由於
刷機(ROM系統升級)是Android手機玩家的一大樂趣,特別是一些熱門手機總會有民間高手為其打造豐富的第三方ROM資源,獲得比官方ROM更高的系統版本、