- public void back_Sms(View v) throws IOException {
- StringBuilder sb = new StringBuilder();
- XmlSerializer xml = Xml.newSerializer();
- boolean judge_sd = true;
- File file;
- FileOutputStream fos;
- if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- file = new File(Environment.getExternalStorageDirectory(), "info.xml");
- fos = new FileOutputStream(file);
- xml.setOutput(fos, "utf-8");
- }
- else {
- file = new File(this.getFilesDir(), "info.xml");
- fos = new FileOutputStream(file);
- xml.setOutput(fos, "utf-8");
- judge_sd = false;
- }
- xml.startDocument("utf-8", true);
- xml.startTag(null, "Smss");
- for(Sms s : sms) {
- xml.startTag(null, "sms");
-
- xml.startTag(null, "name");
- xml.text(s.getName());
- xml.endTag(null, "name");
-
- xml.startTag(null, "context");
- xml.text(s.getContext());
- xml.endTag(null, "context");
-
- xml.startTag(null, "number");
- xml.text(s.getNumber());
- xml.endTag(null, "number");
-
- xml.endTag(null, "sms");
- }
- xml.endTag(null, "Smss");
- xml.endDocument();
- fos.close();
- if(judge_sd)
- Toast.makeText(this, "备份SD卡成功", 0).show();
- else
- Toast.makeText(this, "备份手机内存卡成功", 0).show();
-
- }
复制代码 |