程序中调用联系人数据

首先添加一个权限:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
发起一个 Contact Picker
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
重写方法
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data)
  { 
      super.onActivityResult(reqCode, resultCode, data); 
        switch (reqCode) {
             case (PICK_CONTACT) :     
             if (resultCode == Activity.RESULT_OK) {       
             Uri contactData = data.getData();       
             Cursor c =  managedQuery(contactData, null, null, null, null);       
             if (c.moveToFirst()) {         
                String name = c.getString(c.getColumnIndexOrThrow(People.NAME));         
                // TODO Whatever you want to do with the selected contact name.       
                                 }     
                      }     
              
      break; 
               
         }
   }

例如
String[] columns = new String[] {People.NAME};
int[] names = new int[] {R.id.row_entry};
mAdapter = new SimpleCursorAdapter(this, R.layout.mycontacts, C, columns, names);
setListAdapter(mAdapter);

你可能感兴趣的:(C++,c,C#)