views:

71

answers:

0

Hello, I want to write a program to automatically generate the contacts. I also use a special service to add account on emulator. The same account is used on the telephone. Below is my code:

ContentValues values = new ContentValues();
values.put(RawContacts.ACCOUNT_TYPE, "localhost");
values.put(RawContacts.ACCOUNT_NAME, "PC Sync");
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);             

values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.GIVEN_NAME, Gname);
values.put(StructuredName.FAMILY_NAME, Fname);
values.put(StructuredName.MIDDLE_NAME, Mname);
getContentResolver().insert(Data.CONTENT_URI, values);

The program is working on emulator and adds contacts, but on HTC the program only process adding no contacts. I can't understand what the problem can be.