Hi , you can try the contact manager example included in sdk it uses batch operation which is preferred method over content values
Specify account name null and type also null It will surely insert. Regards Subrat On Feb 19, 7:05 pm, Pranav <[email protected]> wrote: > Hi ivar, > > Thanks for you reply with Suggestion. As you suggest me, i did it > properly but it's not storing contacts permanently in phonebook. When > i close emulator and start it again, it gives me only last record > which i have entered. I did those things in api version-4. > > Today, i tried to add contacts using api version-5&6. I am able to > write contacts in phonebook as well as i can also ready it properly. > But somehow it's not display in the actual phonebook of emulator and > it's not giving me any error or warning while adding contacts. What is > missing in my code? Is there any authority or something... which i can > apply on my application or any code? > > Here is my code which i have tried. Please have a look inside. > Note: I have tested this code using api version-5&6. > > package com.android.TestContacts; > > import android.app.Activity; > import android.content.ContentResolver; > import android.content.ContentUris; > import android.content.ContentValues; > import android.database.Cursor; > import android.net.Uri; > import android.os.Bundle; > import android.provider.ContactsContract; > import android.provider.ContactsContract.Data; > import android.provider.ContactsContract.RawContacts; > import > android.provider.ContactsContract.CommonDataKinds.StructuredName; > import android.widget.TextView; > > 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); > > ContentValues values = new ContentValues(); > values.put(RawContacts.ACCOUNT_TYPE, ""); > values.put(RawContacts.ACCOUNT_NAME, ""); > 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.DISPLAY_NAME, "Misha"); > getContentResolver().insert(Data.CONTENT_URI, values); > > contentResolver = getContentResolver(); > cursor = > contentResolver.query(ContactsContract.Data.CONTENT_URI, null, null, > null, null); > if (cursor.getCount() > 0) { > while (cursor.moveToNext()) { > String id = > cursor.getString(cursor.getColumnIndex(ContactsContract.Data._ID)); > System.out.println("ID: "+id); > > String name = > cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); > System.out.println("Name: "+name); > tv.append("ID: "+id+" "+"Name: "+name+"\n"); > } > } > }} > > In short, the contacts hasn't displayed in the actual phonebook of > emulator. Can anybody give me idea regarding my problem? How to > resolve this issue? Please give me advice to resolve this issue. > > Thanks. > > Regards, > _____________ > Pranav -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

