【问题标题】:How android store contact's vcard data?android如何存储联系人vcard数据?
【发布时间】:2012-01-10 04:53:38
【问题描述】:

通常我们使用此代码来读取联系人的 v-card 数据。

 AssetFileDescriptor afd = context.getContentResolver().openAssetFileDescriptor(
            Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey), "r");

v-card 数据物理存储在哪里?我查看了contacts2.db,它也不存在吗?

有人知道openAssetFileDescriptor 的工作原理吗?

【问题讨论】:

    标签: android android-contacts android-contentprovider


    【解决方案1】:

    Android 在需要时创建 VCard,使用 Contacts APIS 获取信息 我认为它们不会作为 VCard 存储在内部存储器中。 您可以通过android.pim.vcard 包获取更多详细信息 看VCardComposer.java,VCardBuilder.java

    【讨论】:

      【解决方案2】:
      AssetFileDescriptor fd = mContext.getContentResolver()
                              .openAssetFileDescriptor(uri, "r");
      
                      BufferedInputStream fips = new BufferedInputStream(
                              fd.createInputStream());
                      byte[] byteOneLine = new byte[8*1024];
                      while(fips.read(byteOneLine) != -1){
                          output_.write(byteOneLine);
                      }
      

      其中 output_ 是 OutputStream 的一个实例。

      但是,执行“mContext.getContentResolver()openAssetFileDescriptor(uri, "r")”需要很长时间。 当我有 600 个联系人时,它会花费 20 秒。

      寻找更好的方法。

      【讨论】:

        【解决方案3】:

        简单干净的方式:

        在此处查看我的答案以获取更多详细信息:answer

        代码:

        public ArrayList<String> getContactsAsVcards()
        {
            ArrayList<String> vcards = new ArrayList<String>();
            VCardComposer vCardComposer = new VCardComposer(context);
        
            vCardComposer.init();
        
            do {
                String vCard = vCardComposer.createOneEntry();
        
                vcards.add(vCard);
            } while (!vCardComposer.isAfterLast());
        
            return vcards;
        
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-04
          • 1970-01-01
          • 2011-05-21
          • 2011-12-29
          相关资源
          最近更新 更多