Java 无法读取vCard数据:从ez vCard导出
我正在利用ezvcard库从我自己的应用程序中导出联系人数据。我的问题是,无法在我的stock contacts应用程序中读取导出的vcard。这是输出:Java 无法读取vCard数据:从ez vCard导出,java,android,vcf-vcard,Java,Android,Vcf Vcard,我正在利用ezvcard库从我自己的应用程序中导出联系人数据。我的问题是,无法在我的stock contacts应用程序中读取导出的vcard。这是输出: BEGIN:VCARD VERSION:4.0 N:;User Name;;; FN:User Name ORG:Anderson Secondary School TEL;TYPE=work,voice:92365313 PRODID:ez-vcard 0.9.9 END:VCARD BEGIN:VCARD VERSION
BEGIN:VCARD
VERSION:4.0
N:;User Name;;;
FN:User Name
ORG:Anderson Secondary School
TEL;TYPE=work,voice:92365313
PRODID:ez-vcard 0.9.9
END:VCARD
BEGIN:VCARD
VERSION:4.0
N:;All fields 2;;;
FN:All fields 2
ORG:List (All fields)
TEL;TYPE=work,voice:12345678
PRODID:ez-vcard 0.9.9
END:VCARD
下面是我创建vCard的代码
LayoutInflater li = SettingsPortationActivity.this.getLayoutInflater();
View promptsView = li.inflate(R.layout.prompts, null);
fileName = "";
fileNameInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);
fileNameInput.setText(".vcf");
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsPortationActivity.this);
// sets prompts to alertdialog builder
builder.setView(promptsView);
builder.setCancelable(false)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
fileName = fileNameInput.getText().toString();
if (!fileName.trim().isEmpty()) { // has value
FavoritesDatabaseHelper db = new FavoritesDatabaseHelper(getApplicationContext());
List<FavoriteObject> favorites = db.getAllFavorites();
List<VCard> vcards = new ArrayList<VCard>();
String storage_path = Environment.getExternalStorageDirectory().toString() + File.separator + fileName;
File file = new File(storage_path);
Log.d("Directory", String.valueOf(storage_path));
VCardWriter writer = null;
try {
writer = new VCardWriter(file, VCardVersion.V4_0);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < favorites.size(); i++) {
FavoriteObject fav = favorites.get(i);
Log.d("Export fav", "Fav name" + fav.getContactName());
VCard vcard = new VCard();
vcard.setClassification("PUBLIC");
StructuredName n = new StructuredName();
n.setGiven(fav.getContactName());
vcard.setStructuredName(n);
vcard.setFormattedName(new FormattedName(fav.getContactName()));
Organization org = new Organization();
org.addValue(fav.getListName());
vcard.setOrganization(org);
Telephone tel = new Telephone(fav.getContactNumber());
tel.addType(TelephoneType.WORK);
tel.addType(TelephoneType.VOICE);
vcard.addTelephoneNumber(tel);
vcards.add(vcard);
}
try {
for (VCard vcard : vcards) {
try {
writer.write(vcard);
} catch (IOException e) {
e.printStackTrace();
}
}
} finally {
try {
writer.close();
Log.d("Success", "Export success");
Toast.makeText(SettingsPortationActivity.this, "Export Success", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
fileNameInput.setError("Please enter a file name");
}
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
LayoutInflater li=SettingsPortationActivity.this.getLayoutInflater();
View promptsView=li.充气(R.layout.prompts,null);
fileName=“”;
fileNameInput=(EditText)promptsView.findViewById(R.id.editTextDialogUserInput);
fileNameInput.setText(“.vcf”);
AlertDialog.Builder=新建AlertDialog.Builder(设置SportationActivity.this);
//将提示设置为alertdialog builder
builder.setView(promptsView);
builder.setCancelable(false)
.setPositiveButton(“保存”,新建DialogInterface.OnClickListener()){
@凌驾
public void onClick(DialogInterface dialog,int which){
fileName=fileNameInput.getText().toString();
如果(!fileName.trim().isEmpty()){//有值
FavoritesDatabaseHelper db=新的FavoritesDatabaseHelper(getApplicationContext());
List favorites=db.getAllFavorites();
List vcards=new ArrayList();
String storage_path=Environment.getExternalStorageDirectory().toString()+File.separator+文件名;
文件=新文件(存储路径);
Log.d(“目录”,String.valueOf(存储路径));
VCardWriter-writer=null;
试一试{
writer=新VCardWriter(文件,VCardVersion.V4\u 0);
}捕获(IOE异常){
e、 printStackTrace();
}
对于(int i=0;i
您是否真正利用了任何vCard 4.0功能?如果不是这样,我将首先将版本设置为3.0而不是4.0。不幸的是,很少有软件迁移到vCard 4.0
也会将PRODID放在流的开头,因为这可能会帮助一些解析器