People.CONTENT_URI
クエリを 実行するときに連絡先の画像を取得するのは非常に簡単でした。
People.loadContactPhoto(activity, ContentUris.withAppendedId(People.CONTENT_URI, contactId)
連絡先IDを知っていたからです。コールログにアクセスした後、同じことを行う必要があります。と:
String[] strFields = {
android.provider.CallLog.Calls.CACHED_NAME,
android.provider.CallLog.Calls.NUMBER,
};
String strUriCalls="content://call_log/calls";
Uri UriCalls = Uri.parse(strUriCalls);
Cursor cursorLog = this.getContentResolver().query(UriCalls, strFields, null, null, null);
通話履歴からリストを取得しましたが、写真を読み込むために必要な連絡先IDとこれをリンクする方法が見つかりません。アプリはAPIレベル4以降で動作します。
どんな助けでも大歓迎です。ありがとうございました。
以下のクリスチャンによって導かれるように、私のために働く解決策は次のとおりです:
private long getContactIdFromNumber(String number) {
String[] projection = new String[]{Contacts.Phones.PERSON_ID};
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,Uri.encode(number));
Cursor c = getContentResolver().query(contactUri, projection, null, null, null);
if (c.moveToFirst()) {
long contactId=c.getLong(c.getColumnIndex(Contacts.Phones.PERSON_ID));
return contactId;
}
return -1;
}