android 使用vcard示例

  1. FileOutputStream os = null
  2. try
  3. os = VCardTest.this.openFileOutput("Android.vcf", MODE_PRIVATE); 
  4. } catch (FileNotFoundException e1) { 
  5. // TODO Auto-generated catch block 
  6. e1.printStackTrace(); 
  7. }  
  8. OutputStreamWriter writer; 
  9. try
  10. writer = new OutputStreamWriter( 
  11. os); 
  12.        VCardComposer composer = new VCardComposer(); 
  13.        //create a contact  
  14.        ContactStruct contact1 = new ContactStruct(); 
  15.        contact1.name = "Neo"
  16.        contact1.company = "The Company"
  17.        contact1.addPhone(Contacts.Phones.TYPE_MOBILE, "+123456789", null, true); 
  18.        //create vCard representation  
  19.        String vcardString; 
  20. vcardString = composer.createVCard(contact1, VCardComposer.VERSION_VCARD30_INT); 
  21.        //write vCard to the output stream 
  22.        writer.write(vcardString); 
  23.        writer.write("/n"); //add empty lines between contacts 
  24.        // repeat for other contacts  
  25.        // ...  
  26.        writer.close(); 
  27. } catch (UnsupportedEncodingException e) { 
  28. // TODO Auto-generated catch block  
  29. e.printStackTrace(); 
  30. } catch (FileNotFoundException e) { 
  31. // TODO Auto-generated catch block 
  32. e.printStackTrace(); 
  33. } catch (VCardException e) { 
  34. // TODO Auto-generated catch block  
  35. e.printStackTrace(); 
  36. } catch (IOException e) { 
  37. // TODO Auto-generated catch block 
  38. e.printStackTrace(); 
  39. [java] view plain copy print ?
  1. FileOutputStream os = null
  2. try
  3. os = VCardTest.this.openFileOutput("Android.vcf", MODE_PRIVATE); 
  4. } catch (FileNotFoundException e1) { 
  5. // TODO Auto-generated catch block 
  6. e1.printStackTrace(); 
  7. }  
  8. OutputStreamWriter writer; 
  9. try
  10. writer = new OutputStreamWriter( 
  11. os); 
  12.        VCardComposer composer = new VCardComposer(); 
  13.        //create a contact 
  14.        ContactStruct contact1 = new ContactStruct(); 
  15.        contact1.name = "Neo"
  16.        contact1.company = "The Company"
  17.        contact1.addPhone(Contacts.Phones.TYPE_MOBILE, "+123456789", null, true); 
  18.        //create vCard representation 
  19.        String vcardString; 
  20. vcardString = composer.createVCard(contact1, VCardComposer.VERSION_VCARD30_INT); 
  21.        //write vCard to the output stream 
  22.        writer.write(vcardString); 
  23.        writer.write("/n"); //add empty lines between contacts 
  24.        // repeat for other contacts 
  25.        // ... 
  26.        writer.close(); 
  27. } catch (UnsupportedEncodingException e) { 
  28. // TODO Auto-generated catch block 
  29. e.printStackTrace(); 
  30. } catch (FileNotFoundException e) { 
  31. // TODO Auto-generated catch block 
  32. e.printStackTrace(); 
  33. } catch (VCardException e) { 
  34. // TODO Auto-generated catch block 
  35. e.printStackTrace(); 
  36. } catch (IOException e) { 
  37. // TODO Auto-generated catch block 
  38. e.printStackTrace(); 
FileOutputStream os = null; try { os = VCardTest.this.openFileOutput("Android.vcf", MODE_PRIVATE); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } OutputStreamWriter writer; try { writer = new OutputStreamWriter( os); VCardComposer composer = new VCardComposer(); //create a contact ContactStruct contact1 = new ContactStruct(); contact1.name = "Neo"; contact1.company = "The Company"; contact1.addPhone(Contacts.Phones.TYPE_MOBILE, "+123456789", 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(); } 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(); }

你可能感兴趣的:(android 使用vcard示例)