10

I am trying to write an app that store data for the user for each contacts he chooses. I want to add to each user a custom provider (like facebook does) that on press will open my app and allow the user to review the stored data. I have created a custom provider following this guide: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/

but the custom provider does not appear on my contact list, I have tried to change my MIME_TYPE to vnd.com.google.cursor.item/contact_user_defined_field that didnt help either (when using third party app it showed my provider but without my icon)

my contact definition is this:

<ContactsSource xmlns:android="http://schemas.android.com/apk/res/android">
 <ContactsDataKind
  android:icon="@drawable/ic_launcher"
  android:mimeType="vnd.android.cursor.item/vnd.MyPackageName.profile"
  android:summaryColumn="data2"
  android:detailColumn="data3"
  android:detailSocialSummary="true" />
</ContactsSource>

and my relevant code is this:

String MIME_TYPE  "vnd.android.cursor.item/vnd.MyPackageName.profile";

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex =ops.size();//(int)Contact_RAW_ID;
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
   .withValue(RawContacts.ACCOUNT_TYPE, null)
   .withValue(RawContacts.ACCOUNT_NAME,null )
   .build());

ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
   .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
   .withValue(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE)
   .withValue(Phone.NUMBER, "9X-XXXXXXXXX")
   .build());

ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
   .withValueBackReference(Data.RAW_CONTACT_ID, 0)
   .withValue(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE)
   .withValue(StructuredName.DISPLAY_NAME, "John Doe")
   .build());  

ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
   .withValueBackReference(Data.RAW_CONTACT_ID, 0)
   .withValue(Data.MIMETYPE,Email.CONTENT_ITEM_TYPE)
   .withValue(Email.ADDRESS, "John Doe")
   .build());

ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
   .withValueBackReference(Data.RAW_CONTACT_ID, 0)
   .withValue(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE)
   .withValue(Phone.NUMBER, "1234567890")
   .build());

ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
    .withValueBackReference(Data.RAW_CONTACT_ID, 0)
    .withValue(Data.MIMETYPE,MIME_TYPE)
    .withValue(Data.DATA1, "Custom Field")
    .withValue(Data.DATA2, "Custom Field Header")
    .withValue(Data.DATA3, "Custom Field Body")
    .build());

ContentProviderResult[] res = CallerActivity.getContentResolver().applyBatch      
 (ContactsContract.AUTHORITY, ops);

Edit (06/01/2013): managed to fix it, if you want to make your contact visible make sure that the account name you give the provider is the name as the account of the contact.

now I have a diferent problem, in 4.0 devices the contacts becomes duplicates of each other I tried to do manually aggregation but in some devices it works and in some it doesn't.

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
Juda Hocman
  • 101
  • 1
  • 5
  • Here is an example for your specific requirements https://github.com/nemezis/SampleContacts – Raj008 Oct 22 '13 at 14:12

0 Answers0