The principle of SMS Backup
The principle of SMS backup. is to use the content provider to read the text messages and then save them.
public class Smsbackuputils {//Callback interface public interface Smsbackupcallback {/** * SMS Backup before call * @param Total text message number */public VO ID beforesmsbackup (int total),/** * SMS call in Call * @param progress SMS Progress */public void Progresssmsbackup (int progress);} /** * SMS Backup method, back up to the XML file, because the XML file cross-platform strong This is a time-consuming operation, should be placed in a sub-thread running * * @param context Context * @param path backup to which route * @throws exceptio n */public static void Smsbackup (context context, String Path,smsbackupcallback callBack) throws Exception {//XML serializer XML Serializer serializer = Xml.newserializer (); File File = new file (path); FileOutputStream fos = new FileOutputStream (file),//Set parameter Serializer.setoutput (FOS, "utf-8");// Start Serializer.startdocument ("Utf-8", true); Serializer.starttag (null, "SMSS"); Contentresolver resolver = Context.getcontentresolver (); Uri uri = uri.parse ("content://sms");//Includes all text messages cursor cursor = resolver.query (URI, new string[] {"Address", "date", "type", "Body"}, NULL, NULL, NULL);/*dialog.setmax (Cursor.getcount ());p Rogressbar1.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 ");p rogress++;/*dialog.setprogress (Progress);p rogressbar1.setprogress (progress); */ Callback.progresssmsbackup (progress); Systemclock.sleep (1000);} Cursor.close (); Serializer.endtag (null, "SMSS"); Serializer.enddocument ();}}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Android Development _ Backup SMS