public class MainActivity extends Activity {
String tag = null;
ListView list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView)findViewById(R.id.list_Contact);
getList();
}
private void getList() {
// TODO Auto-generated method stub
// 주소록 URI
Uri people = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
// 검색할 컬럼 정하기
String[] projection = new String[] {
ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(people, projection, null, null, null); // 전화번호부 가져오기
int end = cursor.getCount(); // 전화번호부의 갯수 세기
Log.d(tag, "end = "+end);
String[] name = new String[end]; // 전화번호부의 이름을 저장할 배열 선언
String[] phone = new String[end];
int count = 0;
if(cursor.moveToFirst())
{
// 컬럼명으로 컬럼 인덱스 찾기
int idIndex = cursor.getColumnIndex(Phone._ID);
int nameIndex = cursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneIndex = cursor.getColumnIndex(Phone.NUMBER);
do
{
// 요소값 얻기
int id = cursor.getInt(idIndex);
name[count] = cursor.getString(nameIndex);
phone[count] = cursor.getString(phoneIndex);
// LogCat에 로그 남기기
Log.d(tag, "id = " + id +", name["+count+"]=" + name[count]);
count++;
Log.d(tag, "id, count=" + id + "," + count +", 이름 =" + name[count] +", 번호=" +phone[count]);
} while(cursor.moveToNext() || count > end);
}
}
}
자신의 전화번호부로 이동해 거기에서 자신이 선택한 전화번호들을 가져오는 건데요
기본적으로 하나를 선택해서 지정된 곳에 가져오는 것 까지는 했는데
전화번호를 여러개 선택해서 가져오는 것을 할라 하는데 안되는데 뭐가 문제인지 좀 봐주세요