package com.ylt.contactsDemo;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ContactsDemoActivity extends Activity {
/** Called when the activity is first created. */
private Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
toContacts();
}
});
}
void toContacts() {
Intent it = new Intent(Intent.ACTION_INSERT, Uri.withAppendedPath(
Uri.parse("content://com.android.contacts"), "contacts"));
it.setType("vnd.android.cursor.dir/person");
// it.setType("vnd.android.cursor.dir/contact");
// it.setType("vnd.android.cursor.dir/raw_contact");
// 联系人姓名
it.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, "张三");
// 公司
it.putExtra(android.provider.ContactsContract.Intents.Insert.COMPANY,
"北京XXXXXX公司");
// email
it.putExtra(android.provider.ContactsContract.Intents.Insert.EMAIL,
"123456@qq.com");
// 手机号码
it.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE,
"010-1234567");
// 单位电话
it.putExtra(
android.provider.ContactsContract.Intents.Insert.SECONDARY_PHONE,
"18600001111");
// 住宅电话
it.putExtra(
android.provider.ContactsContract.Intents.Insert.TERTIARY_PHONE,
"010-7654321");
// 备注信息
it.putExtra(android.provider.ContactsContract.Intents.Insert.JOB_TITLE,
"名片");
startActivity(it);
}
}