Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.x: Get custom account type listet in contacts

I'm trying to write my own Sync Adapter for android. I'm digging through the Sample Sync Adapter from SDK but it's horribly undocumented. I can make the contacts appear in the contacts app. But im unable to edit them or create new ones.

It's very hard to find any information on how to get my own account type listed for creation in the default contacts app or make them editable. I don't want to add any custom stüff only fields and data already supported by android.

Can any one point me to a tutorial or samples on how to integrate my sync adapter into the default contacts app (Like the exchange sync)?

  • What neets to be added to AndroidManifest.xml
  • What needs to be added to contacts.xml
  • What needs to be added to syncadapter.xml
  • Is there any code that needs to be added in order to work?

By the way:
I dont care for android versions lower than ICS. I read everywhere that the contacts app of 2.x does not support this but 3.x and above do. 2.x is off the table so I'm looking for the ICS way to do it.

Thanks in Advance

like image 881
tux-rampage Avatar asked Feb 20 '23 22:02

tux-rampage


1 Answers

I think it's a little late to answer this question, but I had this problem and finally solved it. In android 4.x, you can add contact to only three kind of account in android. 1) Google Account, 2) Exchange Account, 3) Writable account, and by writable, it means that your contacts.xml file should contain EditSchema tag. Also you should add the following tag to your manifest file:

<meta-data android:name="android.provider.CONTACTS_STRUCTURE" android:resource="@xml/contacts" />

And about EditSchema, there is a good sample in the following URL:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.3_r1/packages/apps/Contacts/tests/res/xml/test_basic_contacts.xml

You just need to copy above xml file's content and paste it in your contacts.xml file.(You can customize the xml, if you want) And everything is done!

like image 102
Hazhir Avatar answered Mar 04 '23 17:03

Hazhir