特定の連絡先の写真を取得する必要があるアプリケーションがあります。連絡先の電話番号を知っていますが、ContentResolverまたはその他のフォームを使用して電話番号で連絡先の写真が存在する場合、その写真を取得する方法はありますか?探していましたが、答えが見つかりませんでした。
電話番号を使用して連絡先の写真が存在する場合はそれを取得することの重要性を強調したいと思います。ありがとうございました。
特定の連絡先の写真を取得する必要があるアプリケーションがあります。連絡先の電話番号を知っていますが、ContentResolverまたはその他のフォームを使用して電話番号で連絡先の写真が存在する場合、その写真を取得する方法はありますか?探していましたが、答えが見つかりませんでした。
電話番号を使用して連絡先の写真が存在する場合はそれを取得することの重要性を強調したいと思います。ありがとうございました。
さて、私はついにFacebookの写真を追加する方法を理解しました。この方法では、必要なFacebookの写真を電話番号で追加します。
public Bitmap getFacebookPhoto(String phoneNumber) {
Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Uri photoUri = null;
ContentResolver cr = this.getContentResolver();
Cursor contact = cr.query(phoneUri,
new String[] { ContactsContract.Contacts._ID }, null, null, null);
if (contact.moveToFirst()) {
long userId = contact.getLong(contact.getColumnIndex(ContactsContract.Contacts._ID));
photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, userId);
}
else {
Bitmap defaultPhoto = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_menu_report_image);
return defaultPhoto;
}
if (photoUri != null) {
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(
cr, photoUri);
if (input != null) {
return BitmapFactory.decodeStream(input);
}
} else {
Bitmap defaultPhoto = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_menu_report_image);
return defaultPhoto;
}
Bitmap defaultPhoto = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_menu_report_image);
return defaultPhoto;
}
これを行う簡単な方法はないと思います。しかし、私はあなたが電話の連絡先を調べて、それがあなたが一致させようとしているものであるかどうか各番号をチェックすることができると思います。
とにかく番号は順序付けられていないので、それをより効率的にする方法はありません。順序付けられていないリストでの検索は、この問題を処理する必要があることをお勧めしますが、それらをトラバースすることによって実行されます。Androidが、私が知らない順序付きリストにすべての番号を保持していない限り。
次のような操作を行うことで、連絡先をトラバースできます。
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Boolean.parseBoolean(hasPhone)) {
// You know it has a number so now query it like this
Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
cursor.close();
これはあなたのタスクに対する完全な解決策ではありませんが、上記のコードを変更することで、うまくいくと思います。:-)