我已經寫了下面的代碼來添加新的聯繫人在android電話簿,它工作,但是當我打開聯繫人菜單,我看不到添加的新聯繫人。任何人都可以幫我找出這裏有什麼問題嗎?如何在android中添加新的聯繫人
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);
}
}
}
此鏈接可usefuk到u http://saigeethamn.blogspot.com/2009/09/android-developer-tutorial-part-10.html – 2011-01-20 07:15:42
感謝üParag Saigeethamn的博客也很有幫助 – 2011-01-20 10:42:53
但對於舊版本的Android – 2011-01-20 10:53:14