1
iは、プロバイダが、私は特定のアカウントのすべての連絡先を取得しようとしているイベントなど読書の誕生日、無効な列
でどのように機能するかを理解するためにいくつかのテストをやって、その後に各連絡先の詳細を読みます存在する場合は誕生日を取得します。
私は最初に1回でそれをやろうとしましたが、プロバイダの知識が不足していましたので、2段階でそれをやろうとしています。
私はこの行の無効な列取得:どのように私は私が望むデータを取得するために、2番目のクエリを向上させることができますcontact_idがここでの問題である カーソルcursor = cr.query(URI、投影、[...] を。 ?私はどこにもなっていないコードに様々な改造を試みた
おかげで、私が使用し
コード:。。
private void readContacts(){
Cursor contByAccCursor = getContactsByAccounts();
getContactsBirthdays(contByAccCursor);
}
private Cursor getContactsByAccounts() {
Uri uri = ContactsContract.RawContacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.RawContacts.CONTACT_ID,
ContactsContract.RawContacts.ACCOUNT_TYPE
};
String where = ContactsContract.RawContacts.ACCOUNT_TYPE + " IN ('com.google', 'vnd.sec.contact.phone', 'com.skype.contacts.sync')";
return activity.getContentResolver().query(uri,
projection,
where,
null,
null);
}
private void getContactsBirthdays(Cursor filteredContacts) {
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
//ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,
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 + " AND " +
ContactsContract.CommonDataKinds.Event.CONTACT_ID + "= ?";
String[] selectionArgs;
String sortOrder = null;
StringBuffer sb = new StringBuffer();
ContentResolver cr = activity.getContentResolver();
int accTypeCol = filteredContacts.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE);
while(filteredContacts.moveToNext()){
selectionArgs = new String[] {
ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
filteredContacts.getString(filteredContacts.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID))
};
Cursor cursor = cr.query(uri,
projection,
where,
selectionArgs,
sortOrder);
if(cursor.moveToNext()){
String dName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
String bDay = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
String accType = filteredContacts.getString(accTypeCol);
sb.append(dName + "("+accType+")" + " - " + bDay);
sb.append("\n");
}
}
Log.d(TAG, sb.toString());
}