vcard (vers. 3.0) を Android の連絡先に自動的にインポートしようとしています。連絡先マネージャーには、sd カードに保存されている vcf ファイルを連絡先にインポートするオプションがあります。ファイルを渡してこの機能をトリガーするにはどうすればよいですか?
5950 次
1 に答える
3
私は自分のプロジェクトの1つに次のソリューションを使用しました。それは完璧に機能しました。vCard lib として、vcard バージョン 3.0 もサポートする cardme v.0.26 を使用しました。
注: ファイル名は 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 が文字列 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);
于 2011-08-23T00:39:17.910 に答える