I am able to retrieve contact name from emulator phonebook using the above code:
Using java Syntax Highlighting
- public class TestContacts extends Activity {
- /** Called when the activity is first created. */
- ContentResolver contentResolver;
- Cursor cursor;
- String id, name;
- TextView tv;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- tv = (TextView)findViewById(R.id.txtView);
- contentResolver = getContentResolver();
- cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
- if (cursor.getCount() > 0) {
- while (cursor.moveToNext()) {
- String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
- System.out.println("ID: "+id);
- String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
- System.out.println("Name: "+name);
- tv.append("ID: "+id+" "+"Name: "+name+"n");
- }
- }
- }
- }
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.
Using java Syntax Highlighting
- ...
- ContentValues values = new ContentValues();
- values.put(People.NAME, "Test");
- Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
- if(uri == null){
- System.out.println("NEW URI");
- }
- ...
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

