Автоматический импорт vcard 3.0 в контакты Android (Android 2.1) - PullRequest
2 голосов
/ 10 октября 2010

Я пытаюсь автоматически импортировать vcard (версия 3.0) в контакты Android.В диспетчере контактов есть возможность импортировать в контакты файл vcf, сохраненный на sd-карте.Как я могу вызвать эту функцию при передаче файла?

Ответы [ 2 ]

3 голосов
/ 23 августа 2011

Я использовал для одного из своих проектов следующее решение.Это сработало отлично.В качестве библиотеки 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.
         */

// эта переменная содержит вашу vCard в виде строки String 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);
0 голосов
/ 29 мая 2014

Используйте приложение Contacts VCF для импорта контактов с SD-карты / телефона в контакты в мобильных телефонах Android.

Вот ссылка для загрузки приложения ContactsVcf

...