添加自定义MIME类型的机器人接触自定义、机器人、类型、MIME

由网友(参观结束.)分享简介:我试图写一个应用程序,存储数据为用户他选择的每个联系人。我要添加到每个用户自定义提供(如Facebook一样)上preSS将打开我的应用程序,并允许用户查看存储的数据。我创建了一个自定义提供本指南以下内容:http://www.c99.org/2010/01/23/writing-an-android-syn...

我试图写一个应用程序,存储数据为用户 他选择的每个联系人。 我要添加到每个用户自定义提供(如Facebook一样) 上preSS将打开我的应用程序,并允许用户查看存储的数据。 我创建了一个自定义提供本指南以下内容: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/

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/

自定义提供没有出现我的联系人列表中, 我试图改变我的 MIME_TYPE vnd.com.google.cursor.item / contact_user_defined_field 这没有帮助或者(当使用第三方应用程序,这表明我的供应商,但没有我的图标)

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>

和我的相关code是这样的:

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);

修改(2013年6月1日): 设法解决它, 如果你想使你的联系人可见确保帐户名称你给供应商 是名称作为接触的帐户。

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.

现在我有一个diferent问题,在4.0的设备的接触变得相互重复的 我试图做手工汇聚但在某些设备上它的工作原理,并在一些没有。

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.

推荐答案

最好的例子这一要求的https:// github上.COM / nemezis / SampleContacts

阅读全文

相关推荐

最新文章