Android developer _ backup SMS
Zookeeper
Principles of text message backup
The principle of text message backup is to use the content provider to read and save the text message.
Public class SmsBackupUtils {// callback interface public interface SmsBackupCallback {/*** total number of messages called * @ param total text messages */public void beforeSmsbackup (int total) before SMS backup ); /*** call * @ param progress SMS progress */public void progressSmsbackup (int progress);}/*** to back up the SMS, back up the file to an xml file because the xml file is highly cross-platform. This is a time-consuming operation, it should be placed in the Child thread to execute ** @ param context Context * @ param path which path to back up * @ throws Exception */public static void smsBackup (context, String path, SmsBackupCallback callBack) throws Exception {// xml serializer XmlSerializer serializer = Xml. newSerializer (); File file = new File (path); FileOutputStream fos = new FileOutputStream (file); // you can specify the serializer parameter. setOutput (fos, "UTF-8"); // start serializer. startDocument ("UTF-8", true); serializer. startTag (null, "smss"); ContentResolver resolver = context. getContentResolver (); Uri uri = Uri. parse ("content: // sms"); // contains all sms Cursor cursor = resolver. query (uri, new String [] {"address", "date", "type", "body"}, null);/* dialog. setMax (cursor. getCount (); progressBar1.setMax (cursor. getCount (); */callBack. beforeSmsbackup (cursor. getCount (); int progress = 0; while (cursor. moveToNext () {serializer. startTag (null, "sms"); serializer. startTag (null, "address"); String address = cursor. getString (0); serializer. text (address); serializer. endTag (null, "address"); serializer. startTag (null, "date"); String date = cursor. getString (1); serializer. text (date); serializer. endTag (null, "date"); serializer. startTag (null, "type"); String type = cursor. getString (2); serializer. text (type); serializer. endTag (null, "type"); serializer. startTag (null, "body"); String body = cursor. getString (3); serializer. text (body); serializer. endTag (null, "body"); serializer. endTag (null, "sms"); progress ++;/* dialog. setProgress (progress); progressBar1.setProgress (progress); */callBack. progressSmsbackup (progress); SystemClock. sleep (1000);} cursor. close (); serializer. endTag (null, "smss"); serializer. endDocument ();}}