【问题标题】:Import a vcard 3.0 automatically into android contacts (Android 2.1)将 vcard 3.0 自动导入 android 联系人 (Android 2.1)
【发布时间】:2010-10-10 07:08:27
【问题描述】:

我正在尝试将 vcard(版本 3.0)自动导入到 android 联系人中。 在联系人管理器中有一个选项可以将存储在 sd 卡上的 vcf 文件导入到联系人中。如何通过移交文件来触发此功能?

【问题讨论】:

    标签: android import contacts vcf-vcard


    【解决方案1】:

    我在我的一个项目中使用了以下解决方案。它工作得很好。作为 vCard 库,我使用了 cardme v.0.26,它也支持 vcard 3.0 版。

    注意:文件名存储在 res/values/strings.xml...

            /*
             * Create file. This file has to be readable, otherwise the contact
             * application cannot access the file via URI to read the vcard
             * string.
             */
    

    // 此 var 包含您的 vCard 作为字符串 字符串 vcardString;

            FileOutputStream fOut = openFileOutput(
                    getResources().getText(R.string.app_vcard_file_name)
                            .toString(), MODE_WORLD_READABLE);
            osw = new OutputStreamWriter(fOut);
            // write vcard string to file
            osw.write(vcardString);
            // ensures that all buffered bytes are written
            osw.flush();
        } catch (NotFoundException e) {
            // ..
        } catch (IOException e) {
            // ...
        } finally {
            if (osw != null) {
                try {
                    osw.close();
                } catch (IOException e) {
                    // ...
                }
            }
        }
        // let the os handle the import of the vcard to the Contacts
        // application
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setDataAndType(Uri.parse("file://"
                + getFileStreamPath(
                        getResources().getText(R.string.app_vcard_file_name)
                                .toString()).getAbsolutePath()), "text/x-vcard");
        startActivity(i);
    

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      • 2011-08-24
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多