ContactsContract.Groups.CONTENT_URI 를 이용하여 연락처 그룹 정보 가져오기

 

private void getGroup() {

Uri uri = ContactsContract.Groups.CONTENT_URI;

String[] projection = new String[] {
    ContactsContract.Groups._ID,
    ContactsContract.Groups.TITLE,
    ContactsContract.Groups.ACCOUNT_NAME,
    ContactsContract.Groups.ACCOUNT_TYPE,
    ContactsContract.Groups.DELETED,
    ContactsContract.Groups.GROUP_VISIBLE
};
//  String selection = ContactsContract.Groups.DELETED + "=0" + " AND " +
//      ContactsContract.Groups.GROUP_VISIBLE + "=1";

String selection = null;
String sortOrder = null;
Cursor cursor = managedQuery(uri, projection, selection, null, sortOrder);
String groupType = null;
String groupTitle = null;
String accountName = null;
  

while (cursor.moveToNext()) {

Log.d(TAG, "Id ===> " + cursor.getString(0));

Log.d(TAG, "Title ===> " + cursor.getString(1));
Log.d(TAG, "Account Name ===> " + cursor.getString(2));
Log.d(TAG, "Account Type ===> " + cursor.getString(3));
Log.d(TAG, "Deleted ===> " + cursor.getString(4));
Log.d(TAG, "Visible ===> " + cursor.getString(5));
   
groupTitle = cursor.getString(1);
groupType = cursor.getString(3);

getGroupSummaryCount(cursor.getString(0));

}

}

 

ACCOUNT_TYPE 은 그룹이 휴대폰 자체 그룹인지 메일 등 다른 데에서 동기화된 그룹인지를 알려준다.

ACCOUNT_NAME 은 메일 등에서의 그룹이면 메일을 알려준다.

그리고 DELETED 은 그룹이 삭제되었음에도 테이블에서는 사라지지 않아서 조건에 붙여야 했다.  

GROUP_VISIBLE 은 그룹의 visible 상태를 리턴하는데

갤럭시 넥서스에서 외부에서 동기화된 그룹의 visible이 0으로 나왔다. 그래서 조건으로 넣지 않았다.

 

그룹의 멤버수를 알기 위해서 ContactsContract.Groups.CONTENT_SUMMARY_URI 를 이용하면 된다.

 

private void getGroupSummaryCount(String groupId) {

Uri uri = ContactsContract.Groups.CONTENT_SUMMARY_URI;

String[] projection = new String[]  { 

ContactsContract.Groups.SUMMARY_COUNT,
ContactsContract.Groups.ACCOUNT_NAME,
ContactsContract.Groups.ACCOUNT_TYPE

};
String selection = ContactsContract.Groups._ID + "=" + groupId;
Cursor cursor = managedQuery(uri, projection, selection, null, null);
int cnt = 0;
while (cursor.moveToNext()) {

Log.w(TAG, item.getGroupTitle() + ",  SummaryCount ===> " + cursor.getInt(0));

cnt = cursor.getInt(0);

}

}

 

Posted by 애이불비
l

Contacts API 를 이용하여 연락처 정보 가져오기

 

private void LoadContacts() {

Uri uri = ContactsContract.Contacts.CONTENT_URI;

String[] projection = new String[] {
    ContactsContract.Contacts._ID,
    ContactsContract.Contacts.DISPLAY_NAME,
    ContactsContract.Contacts.HAS_PHONE_NUMBER };
 

Cursor cursor = managedQuery(uri, projection, null, null, null);
ContactItem item = null;

if (cursor.getCount() > 0) {
    while (cursor.moveToNext()) {
        if (cursor.getInt(2) == 1) 
         LoadPhoneNumbers(cursor.getString(0));
    }

}

}

 

ContactsContract.Contacts.CONTENT_URI 를 이용하여 id 와 name 을 가져온다.

HAS_PHONE_NUMBER 의 결과값이 1일 경우 id 를 넘겨서

ContactsContract.CommonDataKinds.Phone.CONTENT_URI 를 이용하여

해당 id의 전화번호를 가져온다.

 

private void LoadPhoneNumbers(String id) {

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

String[] projection = new String[] {

ContactsContract.CommonDataKinds.Phone.TYPE, 

ContactsContract.CommonDataKinds.Phone.NUMBER

};

 

String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?";
Cursor cursor = managedQuery(uri, projection, selection, new String[] {id}, null);

while (cursor.moveToNext()) {
   Log.w(TAG, "Number Type ==> " + cursor.getString(0));
   Log.w(TAG, "Number ==> " + cursor.getString(1));

}

}

 

타입별로 전화번호를 가져오는 방법은 대략 다음과 같이 하면 될 것 같다.

 

private String getNumberType(int type) {

String numberType = null;

switch (type) {

case Phone.TYPE_MOBILE:
    numberType = "mobile";
    break;

case Phone.TYPE_HOME:
    numberType = "home";

    break;

......

}

return numberType;

}

 

 

 

Posted by 애이불비
l

 

 

주연 : 이치하라 하야토(토모야), 우에노 주리(아오이)

이 영화는 단순히 우에노 주리가 나와서 봤다.

일상을 보여준다는 느낌이랄까..

역시 일본영화하면 떠오르는 잔잔함이 있었다.

그래서 좋았다..

우에노 주리.. 너무 말랐다!!

 

Posted by 애이불비
l