OSDN Git Service

Create a single VCard file for several contacts
authorDaniel Lehmann <lehmannd@google.com>
Fri, 12 Mar 2010 21:28:14 +0000 (13:28 -0800)
committerDaniel Lehmann <lehmannd@google.com>
Fri, 12 Mar 2010 21:29:14 +0000 (13:29 -0800)
Bug:2501468

Change-Id: I83128ba7f2cf120ec5816a2914b1e9501de526d9

src/com/android/contacts/ContactsListActivity.java
src/com/android/contacts/ImportVCardActivity.java

index c7d158d..e7b5e29 100644 (file)
@@ -1397,16 +1397,21 @@ public class ContactsListActivity extends ListActivity implements View.OnCreateC
                 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();
index d91bb5b..1dd8df5 100644 (file)
@@ -263,7 +263,7 @@ public class ImportVCardActivity extends Activity {
                             // 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 @@ public class ImportVCardActivity extends Activity {
                             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 @@ public class ImportVCardActivity extends Activity {
             } 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,