When I insert a contact, it inserts properly, but I get an “unnamed” entry at the top with no data

和自甴很熟 提交于 2020-01-16 11:23:58

问题


EDIT: I suspect this is resulting from a bug in my HTC sense UI. I would also accept an answer allowing me to test this theory without losing any phone data (i.e. hard reset or otherwise). The phone is an HTC Incredible running Froyo 2.2.

I'm trying to insert a large batch of contacts (parsed into an object through XML, but basically from a custom Object) and I'm having the above problem.

Contacts are adding just fine (to the "com.google" account), but for each contact added, there is a contact "unnamed" added to the top of the list with no data.

ctaList is my "contact to add" list

tempFlr is my object holding all of the contacts to add originally.

Code:

static ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

---------------------------------------------------------------------------
ArrayList<ContactToAdd> ctaList = new ArrayList<ContactToAdd>();
                constructCtaList(tempFlr, ctaList);

                ops.addAll(fillContentProviderOperation(accounts, ctaList,
                        ops));

---------------------------------------------------------------------------

private void constructCtaList(final FrontLineResponse tempFlr,
                ArrayList<ContactToAdd> ctaList) //
{
    for (Customer c : tempFlr.Customers) //
    {
        for (Applicant app : c.Applicants) //
        {
            ContactToAdd cta = constructContactToAdd(c, app);
            ctaList.add(cta);
        }
    }
}

---------------------------------------------------------------------------

protected ArrayList<ContentProviderOperation> addToContacts(
        ContactToAdd cta, int opsLength, Account[] accounts) //
{

    // opsLength is used to store the index to point at the RawContact
    // created here
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
            .withValue(RawContacts.ACCOUNT_TYPE, accounts[0].type)
            .withValue(RawContacts.ACCOUNT_NAME, accounts[0].name).build());

    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, opsLength)
            .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.GIVEN_NAME, cta.FirstName)
            .withValue(StructuredName.FAMILY_NAME, cta.LastName).build());

    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, opsLength)
            .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
            .withValue(Phone.NUMBER, cta.DayWorkPhoneNumber.PhoneNumber)
            .withValue(Phone.TYPE, Phone.TYPE_MOBILE).build());

    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, opsLength)
            .withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE)
            .withValue(Email.DATA1, cta.Email)
            .withValue(Email.TYPE, Email.TYPE_MOBILE).build());

    ops.add(ContentProviderOperation
            .newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, opsLength)
            .withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE)
            .withValue(StructuredPostal.STREET, cta.MailingAddress.Address1)
            .withValue(StructuredPostal.CITY, cta.MailingAddress.City)
            .withValue(StructuredPostal.REGION,
                    cta.MailingAddress.StateCode)
            .withValue(StructuredPostal.POSTCODE,
                    cta.MailingAddress.PostalCode)
            .withValue(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME)
            .build());

    ops.add(ContentProviderOperation
            .newInsert(Data.CONTENT_URI)
            .withValueBackReference(Data.RAW_CONTACT_ID, opsLength)
            .withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE)
            .withValue(StructuredPostal.STREET,
                    cta.ShippingAddress.Address1)
            .withValue(StructuredPostal.CITY, cta.ShippingAddress.City)
            .withValue(StructuredPostal.REGION,
                    cta.ShippingAddress.StateCode)
            .withValue(StructuredPostal.POSTCODE,
                    cta.ShippingAddress.PostalCode)
            .withValue(StructuredPostal.TYPE, StructuredPostal.TYPE_WORK)
            .build());

    return ops;
}

Thanks!


回答1:


It looks like this is a peculiarity of the Sense UI for HTC. This was solved by simply cleansing the data before I inserted it into the ContentProvider.

Hope this helps anybody confused by this!



来源:https://stackoverflow.com/questions/6510361/when-i-insert-a-contact-it-inserts-properly-but-i-get-an-unnamed-entry-at-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!