Android_ Backup Restore Contacts

Source: Internet
Author: User

Package Cn.m15.helper.logic;import Java.io.file;import Java.io.fileinputstream;import java.io.FileOutputStream; Import Android.content.contentresolver;import Android.content.context;import Android.content.intent;import Android.content.res.assetfiledescriptor;import Android.database.cursor;import Android.net.Uri;import Android.os.environment;import Android.provider.contactscontract;public class Contactssyncer extends Syncer {public void Backup (Context context) {Contentresolver CR = Context.getcontentresolver (); Cursor cur = cr.query (ContactsContract.Contacts.CONTENT_URI, null,null, NULL, NULL); int index = Cur.getcolumnindex ( ContactsContract.Contacts.LOOKUP_KEY); FileOutputStream fout;try {fout = new FileOutputStream (environment.getexternalstoragedirectory () + "/GO.VCF"); byte[] data = new byte[1024 * 1];while (Cur.movetonext ()) {String LookupKey = cur.getstring (index); Uri uri = Uri.withappendedpath (ContactsContract.Contacts.CONTENT_VCARD_URI, LookupKey); Assetfiledescriptor FD = context.getcOntentresolver (). Openassetfiledescriptor (URI, "R"); FileInputStream fin = Fd.createinputstream (); int len = -1;while (len = fin.read (data))! =-1) {fout.write (data, 0, Len);} Fin.close ();} Fout.close ();} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}} public void restore (context context, String filename) {Intent Intent = new Intent (); Intent.setpackage (" Com.android.contacts "); Uri uri = uri.fromfile (new File); Intent.setaction (Intent.action_view); Intent.setdataandtype (URI, "text/ X-vcard "); context.startactivity (intent);}}

Android_ Backup Restore Contacts

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.