2017-12-21 18 views
0

ich bereits benutzerdefiniertes Konto mit Authenticator-Service & mein Konto erstellt haben bekommt erstellt successfully.This ist, wie ich Kontakt habe und fügte hinzu:Contact Sync-Adapter zeigt „Telefon nur, nicht synchronisierten Kontakt“

ContentResolver resolver = context.getContentResolver(); 
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 

    ops.add(ContentProviderOperation 
      .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.RawContacts.CONTENT_URI, true)) 
      .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, context.getResources().getString(R.string.app_name)) 
      .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, context.getResources().getString(R.string.account_type)) 
      .withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT) 
      .build()); 

    ops.add(ContentProviderOperation 
      .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI, true)) 
      .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 
      .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) 
      .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name) 
      .build()); 

    ops.add(ContentProviderOperation 
      .newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI, true)) 
      .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 
      .withValue(ContactsContract.Data.MIMETYPE, context.getResources().getString(R.string.mime_type)) 
      .withValue(ContactsContract.Data.DATA1, context.getResources().getString(R.string.app_name)) 
      .withValue(ContactsContract.Data.DATA2, context.getResources().getString(R.string.app_name)) 
      .withValue(ContactsContract.Data.DATA3, context.getResources().getString(R.string.app_name)) 
      .build()); 

    ops.add(ContentProviderOperation. 
      newInsert(ContactsContract.Data.CONTENT_URI) 
      .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) 
      .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) 
      .withValue(ContactsContract.Contacts._ID, id) 
      .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE).build() 
    ); 
    Log.e(TAG, "contact added: " + name + ", " + number); 

    try { 
     resolver.applyBatch(ContactsContract.AUTHORITY, ops); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

Telefon-Kontakte zeigt dies: "Nur Telefon, nicht synchronisierter Kontakt". Ich kann nicht herausfinden, was falsch ist.

Antwort

0

Ich hatte das gleiche Problem. Mein Fehler war, dass ich falsche contentAuthority für meinen Sync-Adapter in der XML-Datei definiert habe.

<sync-adapter 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentAuthority="com.example.syncadapter.provider" 
    android:accountType="com.example.account" 
    android:userVisible="true"/> 

während erforderlichen Wert war

<sync-adapter 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentAuthority="com.android.contacts" 
    android:accountType="com.example.account" 
    android:userVisible="true"/> 
Verwandte Themen