Store contact name in emulator phonebook.

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Store contact name in emulator phonebook.

Postby pranav09 » Thu Feb 18, 2010 9:12 am

Hi all,

I am able to retrieve contact name from emulator phonebook using the above code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class TestContacts extends Activity {
  2.     /** Called when the activity is first created. */
  3.        
  4.         ContentResolver contentResolver;
  5.         Cursor cursor;
  6.         String id, name;
  7.         TextView tv;
  8.        
  9.     @Override
  10.     public void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.main);
  13.        
  14.         tv = (TextView)findViewById(R.id.txtView);
  15.        
  16.         contentResolver = getContentResolver();
  17.         cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
  18.         if (cursor.getCount() > 0) {
  19.                 while (cursor.moveToNext()) {
  20.                         String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
  21.                         System.out.println("ID: "+id);
  22.                        
  23.                         String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
  24.                         System.out.println("Name: "+name);
  25.                         tv.append("ID: "+id+" "+"Name: "+name+"n");
  26.                 }
  27.         }
  28.     }
  29. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


---------------------------------------------------------------------------------------
But i want to add contact name in emulator phonebook and i tried it using the below code but anyhow i could not able to see the contact name in phonebook where as i also trace out something from logcat.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ...
  2. ContentValues values = new ContentValues();
  3. values.put(People.NAME, "Test");
  4. Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
  5. if(uri == null){
  6.      System.out.println("NEW URI");
  7. }
  8. ...
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Infect, when i run the application for adding the new contact, i found this from the logcat:

Code: Select all
02-18 13:18:53.667: DEBUG/AccountManagerService(60): bind attempt failed for Session: expectLaunch false, connected false, stats (0/0/0), lifetime 0.082, getAccountsByTypeAndFeatures, legacy_hosted_or_google
02-18 13:18:53.727: ERROR/ContactsProvider(108): Cannot determine the default account for contacts compatibility
02-18 13:18:53.727: ERROR/ContactsProvider(108): android.accounts.AuthenticatorException: bind failure
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at android.accounts.AccountManager.convertErrorToException(AccountManager.java:659)
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at android.accounts.AccountManager.access$500(AccountManager.java:53)
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at android.accounts.AccountManager$BaseFutureTask$Response.onError(AccountManager.java:566)
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at android.os.Binder.execTransact(Binder.java:287)
02-18 13:18:53.727: ERROR/ContactsProvider(108):     at dalvik.system.NativeStart.run(Native Method)
02-18 13:18:54.037: INFO/ContactAggregator(108): Contact aggregation: 1
02-18 13:18:54.197: INFO/ContactAggregator(108): Contact aggregation complete: 1, 157 ms per contact


After that i had also tried to run the application for retrieving the contacts from phonebook. It works fine and also giving perfect result but somehow it doesn't show me the contact which i have added named "Test" that i could not find in phonebook.

What is really happening inside, i don't know. Can anybody give me any advice or idea or any code to resolve this problem.

Please help me out to resolve this problem.

Thanks.


Regards,
__________
Pranav
User avatar
pranav09
Senior Developer
Senior Developer
 
Posts: 128
Joined: Mon Jan 19, 2009 12:01 pm
Location: Ahmedabad, India

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests