Android联系人未显示在我的自定义帐户中

时间:2018-06-05 07:56:33

标签: android synchronization contacts

我已经成功实施了同步适配器,在设置和联系人帐户屏幕中显示我的帐户。问题是,当我尝试按我的帐户过滤时,Android联系人没有在我的帐户标记下显示任何联系人,只是显示0个联系人。我可以在我的帐户中保存联系人。我需要获取所有联系人,然后逐个添加到我的帐户(在检查服务器后是否使用我的应用程序)。 我需要在应用中显示所有联系人,在我的应用中注册的人以及未注册的人。我怎么能做到这一点。 这是我在SyncAdapter的OnPerformSync方法中的代码:

 @Override
  public void onPerformSync(Account account, Bundle extras, String authority,
    ContentProviderClient provider, SyncResult syncResult) {

    try {

        // see if we already have a sync-state attached to this account. By handing
        // This value to the server, we can just get the contacts that have
        // been updated on the server-side since our last sync-up
        long lastSyncMarker = getServerSyncMarker(account);

        // By default, contacts from a 3rd party provider are hidden in the contacts
        // list. So let's set the flag that causes them to be visible, so that users
        // can actually see these contacts.
        if (lastSyncMarker == 0) {
            ContactManager.setAccountContactsVisibility(getContext(), account, true);
        }

        List<MyDataModel> dirtyContacts;
        List<MyDataModel> updatedContacts;


        final String authtoken = mAccountManager.blockingGetAuthToken(account,
                SyncConstants.AUTHTOKEN_TYPE, NOTIFY_AUTH_FAILURE);

        // Find the local 'dirty' contacts that we need to tell the server about...
        // Find the local users that need to be sync'd to the server...
        dirtyContacts = ContactManager.getDirtyContacts(mContext, account);

        // Send the dirty contacts to the server, and retrieve the server-side changes
         NetworkUtilities.syncContactsWithFirebase(mContext,account, authtoken,
               lastSyncMarker, dirtyContacts, new OnGetContacts() {
                    @Override
                    public void onGetContacts(boolean success, List<MyDataModel> serverContacts) {
                        if (success){
                            List<MyDataModel> updatedContacts = serverContacts;
                            Log.d(TAG, "Calling contactManager's sync contacts");
        long newSyncState = ContactManager.updateContactsNew(mContext,
                account.name,
                updatedContacts,
                groupId,
                lastSyncMarker);
                            if (dirtyContacts.size() > 0) {
                                ContactManager.clearSyncFlags(mContext, dirtyContacts);
                            }
                        }
                    }
                });

这是我的联系人xml:         <ContactsSource xmlns:android="http://schemas.android.com/apk/res/android"> <ContactsDataKind android:mimeType="vnd.android.cursor.item/vnd.myappsyncadapter.profile" android:icon="@mipmap/myapp_icon" android:summaryColumn="data2" android:detailColumn="data3" android:detailSocialSummary="true" /> </ContactsSource>

0 个答案:

没有答案