Android手机系统的手机功能开发例子
/**
* 增加一条联系人
*/
private void insertContactsDialog() {
View view = View.inflate(this, yout.insert_contacts_layout,null);
final EditText username_handle = (EditText) view.findViewById(R.id.insert_contacts_layout_edittext_username);
final EditText password_handle = (EditText) view.findViewById(R.id.insert_contacts_layout_edittext_password);
final AlertDialog.Builder myBuilder = new AlertDialog.Builder(this);
myBuilder.setIcon(android.R.drawable.ic_dialog_info);
myBuilder.setTitle(R.string.insertContacts);
myBuilder.setView(view);
myBuilder.setPositiveButton(R.string.certain,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {
String peopleName = username_handle.getText().toString(); String phoneNum = password_handle.getText().toString();
//信息储存容器
ContentValues contentValues = new ContentValues();
//将联系人名放入ContentValues
contentValues.put(contacts_lable[1], peopleName);
//添加的位置 0为联系人, 1 为联系人+收藏夹 contentValues.put(People.STARRED, 0);
//将名字添加到联系人列表并得到添加的Uri
Uri peopleUri = People.createPersonInMyContactsGroup(getContentResolver(), contentValues);
Log.e("peopleUri:",""+peopleUri.toString());
Uri phoneNumUri = Uri.withAppendedPath(peopleUri, People.Phones.CONTENT_DIRECTORY);
Log.e("phoneNumUri:",""+phoneNumUri.toString());
} //清除信息容器中旧的信息 contentValues.clear(); //放入新的信息 contentValues.put(People.TYPE, People.TYPE_OTHER); contentValues.put(contacts_lable[2], phoneNum); //插入联系人电话信息 getContentResolver().insert(phoneNumUri, contentValues); queryContacts("*");