Android Development _ Backup SMS

Source: Internet
Author: User



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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.