Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1b13711 authored by Daniel Lehmann's avatar Daniel Lehmann
Browse files

Expose the Uri of the newly created contact

Bug: 2448065

Change-Id: Ie1de3c02981ae471b7772cac289a07f0fc870f31
parent 453e60db
Loading
Loading
Loading
Loading
+48 −41
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.pim.vcard;

import android.accounts.Account;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.OperationApplicationException;
import android.database.Cursor;
@@ -1051,7 +1052,7 @@ public class VCardEntry {
        }
    }

    public void pushIntoContentResolver(ContentResolver resolver) {
    public Uri pushIntoContentResolver(ContentResolver resolver) {
        ArrayList<ContentProviderOperation> operationList =
            new ArrayList<ContentProviderOperation>();
        ContentProviderOperation.Builder builder =
@@ -1286,11 +1287,17 @@ public class VCardEntry {
        }

        try {
            resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
            ContentProviderResult[] results = resolver.applyBatch(
                        ContactsContract.AUTHORITY, operationList);
            // the first result is always the raw_contact. return it's uri so
            // that it can be found later
            return results[0].uri;
        } catch (RemoteException e) {
            Log.e(LOG_TAG, String.format("%s: %s", e.toString(), e.getMessage()));
            return null;
        } catch (OperationApplicationException e) {
            Log.e(LOG_TAG, String.format("%s: %s", e.toString(), e.getMessage()));
            return null;
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.pim.vcard;

import android.content.ContentResolver;
import android.net.Uri;
import android.util.Log;

/**
@@ -34,6 +35,7 @@ public class VCardEntryCommitter implements VCardEntryHandler {

    private final ContentResolver mContentResolver;
    private long mTimeToCommit;
    private Uri mLastCreatedUri;

    public VCardEntryCommitter(ContentResolver resolver) {
        mContentResolver = resolver;
@@ -50,7 +52,11 @@ public class VCardEntryCommitter implements VCardEntryHandler {

    public void onEntryCreated(final VCardEntry contactStruct) {
        long start = System.currentTimeMillis();
        contactStruct.pushIntoContentResolver(mContentResolver);
        mLastCreatedUri = contactStruct.pushIntoContentResolver(mContentResolver);
        mTimeToCommit += System.currentTimeMillis() - start;
    }

    public Uri getLastCreatedUri() {
        return mLastCreatedUri;
    }
}
 No newline at end of file