gpt4 book ai didi

android - 按联系人 ID 联系契约(Contract)查找电话号码

转载 作者:太空狗 更新时间:2023-10-29 15:57:35 25 4
gpt4 key购买 nike

我正在尝试通过联系人的 contactId 查找联系人的电话号码,结果返回 - 电话号码: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();
}

最佳答案

试试这个:

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);
}

关于android - 按联系人 ID 联系契约(Contract)查找电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4729551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com