Android vcard uses the sample to generate the VCF file
When we back up the phone contacts, when exporting to the SD card, a VCF file is generated in the SD card to save the contact name and phone number.
The VCard specification allows for public exchange of personal Data exchange (Personal Data Interchange PDI) information, which can be found in traditional paper business cards. The specification defines the format of an Electronic Business card (or vCard).
Using a vcard on Android requires a third-party package:
To copy it into the project and then add the jar, the implementation code is simple, as follows:
if (Environment.getexternalstoragestate (). Equals (environment.media_mounted))//Determine if the memory card exists {OutputStreamWriter Writer File File = new file (Environment.getexternalstoragedirectory (), "example.vcf");//Gets the root path of the memory card, writes EXAMPLE.VCF to the root directory, try { writer = new OutputStreamWriter (new FileOutputStream (file), "UTF-8"); Create a contact Vcardcomposer composer = new Vcardcomposer (); Contactstruct Contact1 = new Contactstruct (); Contact1.name = "John"; Contact1.company = "the Company"; Contact1.addphone (Contacts.Phones.TYPE_MOBILE, "15651865008", null, TRUE); Create VCard representation String vcardstring; vcardstring = Composer.createvcard (Contact1, vcardcomposer.version_vcard30_int); Write VCard to the output stream Writer.write (vcardstring); Writer.write ("/n"); Add empty lines between contacts//Repeat for other contacts//... writer.close (); Toast.maketext (c, "The SD card was successfully imported!) ", Toast.length_short). Show ();} catch (Unsupportedencodingexception e) {//TODO auto-generated catch block E.printstacktrace (); } catch (FileNotFoundException e) {//TODO auto-generated catch block E.printstacktrace (); } catch (Vcardexception e) {//TODO auto-generated catch block E.printstacktrace (); } catch (IOException e) {//TODO auto-generated catch block E.printstacktrace (); }} else{Toast.maketext (c, "Write failed, SD card does not exist!) ", Toast.length_short). Show ();}
To read and write to the memory card, read and Write permissions are added:
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
This allows the contact to be backed up successfully, with the system's own contact software to implement the import. Here is just a simple example of writing data, reading the data in the VCF file example I have and a compression upload, for the students to download,: http://download.csdn.net/detail/pzhtpf/4564761