Android备份本地联系人和插入联系人
一.需要的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
二.获取本地联系人数据:
public void getContacts(View v){
//获取ContentResolver对象
ContentResolver contentResolver=getContentResolver();
//通过联系人id查询每个人对应信息
Cursor cursor=contentResolver.query(Uri.parse("content://com.android.contacts/raw_contacts"),new String[]{"contact_id"},null,null,null);
personList=new ArrayList<Person>();
while (cursor.moveToNext()){
String contacts_id=cursor.getString(0);
//拿到每个联系人id后查询对应的信息
Cursor cursor1=contentResolver.query(Uri.parse("content://com.android.contacts/data"),new String[]{"data1","mimetype"},"contact_id=?",new String[]{contacts_