Android的应用程序了 - 如何获得生日的联系人如何获得、应用程序、联系人、生日

由网友(不断更新)分享简介:我工作的一个Android应用程序,我需要匹配当前的日期,如果积极的,过程中的一些业务逻辑,它需要完整的联系方式,每个联系人的生日。 I am working on an android application for which I need to match the birthday of each contac...

我工作的一个Android应用程序,我需要匹配当前的日期,如果积极的,过程中的一些业务逻辑,它需要完整的联系方式,每个联系人的生日。

I am working on an android application for which I need to match the birthday of each contact against current date and if positive, process some business logic, which needs the complete contact details.

我已经找到了分别读取接触或接触自己的生日,但我很困惑,如何既结合起来。可有人请提供一些指导。

I have found ways to read birthdays of contacts or the contacts themselves separately, but am confused as to how to combine both. Can somebody please provide some direction.

感谢

推荐答案

找到了答案,经过一番寻找出在网络上。这必须做的方法是:

Found the answer after some looking out on the web. The way this has to be done is :

获取联系人列表 对于每个联系人,得到的ContactID 使用的ContactID获取生日

以下是code片断:

ContentResolver cr = getContentResolver(); //getContnetResolver()
String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME };

Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, projection, null, null,
            ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");

while (cur.moveToNext()) {

   Map<String, String> contactInfoMap = new HashMap<String, String>();
   String contactId = cur.getString(cur.getColumnIndex(ContactsContract.Data._ID));
   String displayName =  cur.getString(cur.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));     

    String columns[] = {
         ContactsContract.CommonDataKinds.Event.START_DATE,
         ContactsContract.CommonDataKinds.Event.TYPE,
         ContactsContract.CommonDataKinds.Event.MIMETYPE,
    };

    String where = Event.TYPE + "=" + Event.TYPE_BIRTHDAY + 
                    " and " + Event.MIMETYPE + " = '" + Event.CONTENT_ITEM_TYPE + "' and "                  + ContactsContract.Data.CONTACT_ID + " = " + contactId;

    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME;

    Cursor birthdayCur = cr.query(ContactsContract.Data.CONTENT_URI, columns, where, selectionArgs, sortOrder); 
    if (birthdayCur.getCount() > 0) {
        while (birthdayCur.moveToNext()) {
             String birthday = birthdayCur.getString(birthdayCur.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
        }
    }
    birthdayCur.close();

   }    

    cur.close();
阅读全文

相关推荐

最新文章