Hello,

there seems to be any change from Android 2.1 to Android 2.2 which
throws an Exception when contact account names have spaces.
I use the following code:

mEntityUri = ContactsContract.Groups.CONTENT_URI.buildUpon()
    .appendQueryParameter(ContactsContract.Groups.ACCOUNT_NAME,
mAccountName)
    .appendQueryParameter(ContactsContract.Groups.ACCOUNT_TYPE,
mAccountType)
    .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
    .build();

and later (with the same values):

ContentProviderOperation.Builder builder =
ContentProviderOperation.newInsert(mEntityUri);
Log.v(TAG, "create accountgroup: "+mAccountType+", "+mAccountName);
builder.withValue(ContactsContract.Groups.ACCOUNT_TYPE, mAccountType);
builder.withValue(ContactsContract.Groups.ACCOUNT_NAME, mAccountName);
builder.withValue(ContactsContract.Groups.SYSTEM_ID, mAccountName);
builder.withValue(ContactsContract.Groups.TITLE, mAccountName);
builder.withValue(ContactsContract.Groups.GROUP_VISIBLE, 1);
mBatchOperation.add(builder.build());

mBatchOperation.execute(); // this is line 133 in GroupManager.java

On Android 2.1 this code works fine on Android 2.2 this works fine as
long as there are no spaces in mAccountName.
If there are spaces the following Exception is thrown:

java.lang.IllegalArgumentException: When both specified, ACCOUNT_NAME
and ACCOUNT_TYPE must match; URI:
content://com.android.contacts/groups?account_name=Home%20Address%20Book&account_type=org.dmfs.carddav.account&caller_is_syncadapter=true,
calling user: org.dmfs.carddav.sync, calling package:org.dmfs.carddav.sync
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
at
android.database.DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(DatabaseUtils.java:137)
at
android.content.ContentProviderProxy.applyBatch(ContentProviderNative.java:491)
at
android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:95)
at android.content.ContentResolver.applyBatch(ContentResolver.java:622)
at org.dmfs.contacts.BatchOperations.execute(BatchOperations.java:54)
at org.dmfs.contacts.GroupManager.execute(GroupManager.java:133)
at
org.dmfs.carddav.syncadapter.SyncAdapter.onPerformSync(SyncAdapter.java:124)
at
android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:163)

BatchOperations is implemented like in sampleSyncAdapter.

resolveAccount from ContactsProvider2.java uses a different check now,
maybe the "%20" is not properly replaced.

Is there a known work-around (aside from removing spaces in the account
name)?

cheers

Marten

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to