特定の RAW_CONTACT_ID の DATA テーブルからデータを取得しようとしていますが、空のクエリ出力しか取得できません。ロジックは非常に単純に思えますが、なぜこれが起こるのかわかりません。グーグルで検索しましたが、似たようなものは見つかりませんでした。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
String where = RawContacts.DELETED + "<> 0 and " + RawContacts.ACCOUNT_TYPE + "=?";
Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,
new String[] {RawContacts._ID,
RawContacts.ACCOUNT_NAME,
RawContacts.ACCOUNT_TYPE,
RawContacts.DISPLAY_NAME_PRIMARY
},
where,
new String[] {"Local Phone Account"},
null);
int i = 0;
if (c.getCount() > 0) {
while (c.moveToNext() && i < 10) {
i = i + 1;
// get the id from RawContacts cursor
String rawID = c.getString(c.getColumnIndex(RawContacts._ID));
tv.append("searching RawID " + rawID + "\n" +
"account name: " + c.getString((c.getColumnIndex(RawContacts.ACCOUNT_NAME))) + "\n" +
"account type: " + c.getString(c.getColumnIndex(RawContacts.ACCOUNT_TYPE)) + "\n" +
"display name: " + c.getString(c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY)) + "\n"
);
// create a cursor from Data table for the RawContacts ID
Cursor cur = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID},
Data.RAW_CONTACT_ID + "=?",
new String[] {String.valueOf(rawID)},
null
);
tv.append("found " + cur.getCount() + " matches for id " + String.valueOf(rawID) + "\n");
cur.close();
}
}
setContentView(tv);
}