ContactScontract Lookupの電話番号は連絡先IDによるものです
-
12-10-2019 - |
質問
連絡先による連絡先の電話番号を検索しようとしていますが、BLLの結果が戻ってきています - 電話番号:1
私はその周りで他の例を使用しようとしましたが、カーソルで0カウントを取得し続けています
Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, contactId);
Log.i(TAG, "Locate Contact by Id: " + contactId + " at Uri: " + uri.toString());
Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor.moveToFirst()) {
Log.i(TAG, "Phone Number: " + cursor.getString(cursor.getColumnIndex(Phone.NUMBER)));
}
} finally {
cursor.close();
}
解決 2
私はそれをすることになりました Phone.LOOKUP_KEY
それよりも Phone.CONTACT_ID
;
private HashMap<String, CharSequence> lookupPhoneNumbers(String lookupKey)
{
HashMap<String, CharSequence> numbers = new HashMap<String, CharSequence>();
Cursor cursor = getContext().getContentResolver().query(Phone.CONTENT_URI, null, Phone.LOOKUP_KEY + " = ?", new String[] { lookupKey }, null);
try
{
while (cursor.moveToNext())
{
String phoneNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
int type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE));
CharSequence phoneLabel = Phone.getTypeLabel(getResources(), type, "Undefined");
// boolean isPrimary = (cursor.getInt(cursor.getColumnIndex(Phone.IS_PRIMARY)) == 1);
numbers.put(phoneNumber, phoneLabel);
}
} finally
{
cursor.close();
}
return numbers;
}
他のヒント
これを試して:
private ArrayList<String> getPhoneNumbers(String id)
{
ArrayList<String> phones = new ArrayList<String>();
Cursor cursor = mContentResolver.query(
CommonDataKinds.Phone.CONTENT_URI,
null,
CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (cursor.moveToNext())
{
phones.add(cursor.getString(cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER)));
}
cursor.close();
return(phones);
}
所属していません StackOverflow