I have written following code to add new contact in android phone book, it is working but when i open contact menu, i cannot see the new contact added. Can anyone help me to find out what's wrong here?
import android.app.Activity;
import android.os.Bundle;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.provider.ContactsContract;
import android.widget.TextView;
import android.widget.Toast;
public class AddContacts extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
ContentResolver cr = this.getContentResolver();
ContentValues cv = new ContentValues();
cv.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "New Name");
cv.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "1234567890");
cv.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
cr.insert(ContactsContract.RawContacts.CONTENT_URI, cv);
Toast.makeText(this, "Contact added", Toast.LENGTH_LONG).show();
} catch(Exception e) {
TextView tv = new TextView(this);
tv.setText(e.toString());
setContentView(tv);
}
}
}