Create a single VCard file for several contacts
Bug:2501468
Change-Id: I83128ba7f2cf120ec5816a2914b1e9501de526d9
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index c7d158d..e7b5e29 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -1397,16 +1397,21 @@
return;
}
- ArrayList<Uri> uriList = new ArrayList<Uri>();
+ StringBuilder uriListBuilder = new StringBuilder();
+ int index = 0;
for (;!cursor.isAfterLast(); cursor.moveToNext()) {
- uriList.add(Uri.withAppendedPath(
- Contacts.CONTENT_VCARD_URI,
- cursor.getString(0)));
+ if (index != 0)
+ uriListBuilder.append(':');
+ uriListBuilder.append(Uri.encode(cursor.getString(0)));
+ index++;
}
+ Uri uri = Uri.withAppendedPath(
+ Contacts.CONTENT_MULTI_VCARD_URI,
+ Uri.encode(uriListBuilder.toString()));
- final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
+ final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(Contacts.CONTENT_VCARD_TYPE);
- intent.putExtra(Intent.EXTRA_STREAM, uriList);
+ intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
} finally {
cursor.close();
diff --git a/src/com/android/contacts/ImportVCardActivity.java b/src/com/android/contacts/ImportVCardActivity.java
index d91bb5b..1dd8df5 100644
--- a/src/com/android/contacts/ImportVCardActivity.java
+++ b/src/com/android/contacts/ImportVCardActivity.java
@@ -263,7 +263,7 @@
// Assume that VCardSourceDetector was able to detect the source.
}
String charset = detector.getEstimatedCharset();
- createdUri = doActuallyReadOneVCard(uri, mAccount,
+ doActuallyReadOneVCard(uri, mAccount,
charset, false, detector, mErrorFileNameList);
mProgressDialogForReadVCard.incrementProgressBy(1);
}
@@ -279,14 +279,16 @@
mNeedReview = false;
Log.v("importVCardActivity", "Prepare to review the imported contact");
- // get contact_id of this raw_contact
- final long rawContactId = ContentUris.parseId(createdUri);
- Uri contactUri = RawContacts.getContactLookupUri(getContentResolver(),
- ContentUris.withAppendedId(RawContacts.CONTENT_URI,
- rawContactId));
+ if (createdUri != null) {
+ // get contact_id of this raw_contact
+ final long rawContactId = ContentUris.parseId(createdUri);
+ Uri contactUri = RawContacts.getContactLookupUri(getContentResolver(),
+ ContentUris.withAppendedId(RawContacts.CONTENT_URI,
+ rawContactId));
- Intent viewIntent = new Intent(Intent.ACTION_VIEW, contactUri);
- startActivity(viewIntent);
+ Intent viewIntent = new Intent(Intent.ACTION_VIEW, contactUri);
+ startActivity(viewIntent);
+ }
}
} else {
StringBuilder builder = new StringBuilder();
@@ -338,7 +340,8 @@
} catch (VCardNestedException e) {
Log.e(LOG_TAG, "Never reach here.");
}
- return committer.getLastCreatedUri();
+ final ArrayList<Uri> createdUris = committer.getCreatedUris();
+ return (createdUris == null || createdUris.size() != 1) ? null : createdUris.get(0);
}
private boolean readOneVCardFile(Uri uri, String charset,