我正在构建一个程序,需要在程序开始时自动将联系人添加到联系人列表中。我该怎么做呢?它甚至可能吗?
由于
答案 0 :(得分:3)
是的,这是可能的。以下是您在应用启动时添加亚伯拉罕林肯的方式:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentValues values = new ContentValues();
// Add Abraham Lincoln to contacts and make him a favorite.
values.put(People.NAME, "Abraham Lincoln");
// 1 = the new contact is added to favorites
// 0 = the new contact is not added to favorites
values.put(People.STARRED, 1);
Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
}
}
查看内容提供商:http://developer.android.com/guide/topics/providers/content-providers.html