Hi Dmitri,

thanks for your answer. Because my first mail took a few days until it
appeared on this list I reported this bug myself:
http://code.google.com/p/android/issues/detail?id=14505
You may want to mark it as duplicate.

I still have a question regarding this issue: Are other characters
that I should avoid in account names (e.g. ":" "/" "%")?

And I also have another (maybe related) issue. This one is in Android
2.1 already (I could not check 2.2 or 2.3)

When I create a contact I do this with the following code:

ContentProviderOperation.Builder builder =
ContentProviderOperation.newInsert(mRawEntityUri);
builder.withValue(RawContacts.ACCOUNT_TYPE, mAccountType);
builder.withValue(RawContacts.ACCOUNT_NAME, mAccountName);
builder.withValue(DATA_SOURCE, source);
builder.withValue(DATA_ETAG, etag);
mOperations.add(builder.build());

upon a sync I update it with something like:

ContentProviderOperation.Builder builder =
ContentProviderOperation.newUpdate(mRawEntityUri);
builder.withSelection(ContactsContract.RawContacts._ID + "=?", new
String[] { String.valueOf(mRawContactId) });
builder.withValue(DATA_SOURCE, source);
builder.withValue(DATA_ETAG, etag);
builder.withValue(RawContacts.DIRTY, 0);
builder.withValue(RawContacts.DELETED, 0);
mOperations.add(builder.build());

where DATA_SOURCE = RawContacts.SOURCE_ID and DATA_ETAG =
RawContacts.SYNC1

and "source" is the full URI to a CardDav resource. So it looks like:
https://servername.dom:port/path/to/vcard/123456-7890-abc.vcf

The insert operations work fine, but if I update a contact I get the
following exception when I try to open a contact in the contact app (I
obfuscated the host name):

I/ActivityManager(   59): Starting activity: Intent
{ act=android.intent.action.VIEW dat=content://com.android.contacts/
contacts/lookup/46ehttps://xxx..xxxxxxx..xxx:8443/caldav..php/test/
addresses/C4A77B71-9880-0001-10C2-4CE11DE076B0..vcf/1408 }
D/AndroidRuntime( 5887): Shutting down VM
W/dalvikvm( 5887): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime( 5887): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 5887): android.content.ActivityNotFoundException: No
Activity found to handle Intent { act=android.intent.action.VIEW
dat=content://com.android.contacts/contacts/lookup/46ehttps://
xxx..xxxxxxx..xxx:8443/caldav..php/test/addresses/
C4A77B71-9880-0001-10C2-4CE11DE076B0..vcf/1408 }
E/AndroidRuntime( 5887):        at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:
1408)
E/AndroidRuntime( 5887):        at
android.app.Instrumentation.execStartActivity(Instrumentation.java:
1378)
E/AndroidRuntime( 5887):        at
android.app.Activity.startActivityFromChild(Activity.java:2989)
E/AndroidRuntime( 5887):        at
android.app.Activity.startActivityForResult(Activity.java:2769)
E/AndroidRuntime( 5887):        at
com.android.contacts.ContactsListActivity.onListItemClick(ContactsListActivity.java:
1258)
E/AndroidRuntime( 5887):        at android.app.ListActivity
$2.onItemClick(ListActivity.java:312)
E/AndroidRuntime( 5887):        at
android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 5887):        at
android.widget.ListView.performItemClick(ListView.java:3285)
E/AndroidRuntime( 5887):        at android.widget.AbsListView
$PerformClick.run(AbsListView.java:1640)
E/AndroidRuntime( 5887):        at
android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 5887):        at
android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 5887):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 5887):        at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 5887):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5887):        at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 5887):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 5887):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 5887):        at dalvik.system.NativeStart.main(Native
Method)

if i omit the line

builder.withValue(DATA_SOURCE, source);

in the update code, it works and in the logs I see something like:

I/ActivityManager(   59): Starting activity: Intent
{ act=android.intent.action.VIEW dat=content://com.android.contacts/
contacts/lookup/46ehttps%3A%2F%2Fxxx..xxxxxxx..xxx%3A8443%2Fcaldav..php
%2Ftest%2Faddresses%2FC4A480D3-FB20-0001-40C5-3CC0146EA520..vcf/1406
cmp=com.android.contacts/.ViewContactActivity }

notice the encoded URL this time! I suspect this is another case of an
URI encoding problem.

It seems like my only option is to encode the source with URI-Safe
Base64 (which works fine so far).

Can you confirm this as an Android bug?

cheers

Marten

On 4 Feb., 05:04, Dmitri Plotnikov <dplotni...@google.com> wrote:
> Hi Marten,
>
> I have filed an internal bug for this and will fix it right away.
>
> There is no apparent workaround.  I guess people normally don't run into
> this because most account names are e-mail addresses and thus don't contain
> spaces.
>
> Thank you very much for reporting.
> - Dmitri
>
> On Tue, Feb 1, 2011 at 10:40 AM, Marten Gajda <marten.ga...@freenet.de>wrote:
>
> > 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 android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

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

Reply via email to