Android 2.2 Contact Birthday Date

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:17:14

问题


I am trying to get birthday date from contact details from android 2.2, can someone help me a little bit with the query.

Here is my code:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView contactView = (TextView) findViewById(R.id.contactview);

        Cursor cursor = getContacts();
        while (cursor.moveToNext()) {

            String displayBirthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
            contactView.append("Birthday: ");
            contactView.append(displayBirthday);
            contactView.append("\n");
        }

    }

    private Cursor getContacts() {
        // Run query
        Uri uri = ContactsContract.Data.CONTENT_URI;

        String[] projection = new String[] {
                ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Event.CONTACT_ID,
                ContactsContract.CommonDataKinds.Event.START_DATE
        };

        String where =
                ContactsContract.Data.MIMETYPE + "= ? AND " +
                ContactsContract.CommonDataKinds.Event.TYPE + "=" + ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY;
        String[] selectionArgs = new String[] {ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
        String sortOrder = null;
        return managedQuery(uri, projection, where, selectionArgs, sortOrder);
    }

It seems like something is wrong with this code, I don't get any output on the screen.

I have add in AndroidManifest.xml

Can someone give me some hint what's wrong with my query, thanks a lot.

Best regards, Johnny


回答1:


I ran your code and it seems to work fine.

here is the output screenshot, SGS 2.3.3

Here is the Screenshot:



来源:https://stackoverflow.com/questions/7376980/android-2-2-contact-birthday-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!