我將電話的calllog查詢爲ListView。因此,當用戶長時間點擊某個項目時,會出現一個對話框,其中包含「查看聯繫人」選項。爲了能夠查看聯繫人,意圖需要聯繫人ID。 我的問題是,我並不總是看到正確的聯繫。我點擊彼得,彼得的聯繫表出現了。我點擊莎拉,傑森的聯繫表出現。如何通過電話號碼獲取聯繫人ID
我一定是錯誤地使用了這段代碼。請幫忙。
ContentResolver contentResolver = getContentResolver();
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
Cursor cursor = contentResolver.query(uri, new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
if(cursor!=null) {
while(cursor.moveToNext())
{
String contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
contactid2 = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
}
cursor.close();
}
Intent intent_contacts = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/" + contactid2));
startActivity(intent_contacts);
也許我需要的不是PhoneLookup._ID,而是一些其他的ID。
我也試過費利佩的回答here,也是如此。
編輯:
- 上的HTC Desire HD(2.3.5)獲得正確的接觸中的 病例99%。
- ZTE Blade(2.2)我在60%的案例中獲得了正確的聯繫方式。
- 三星Galaxy Ace(2.3.3)我在5%的情況下獲得了正確的聯繫方式。
這到底是怎麼回事?
爲什麼26?爲什麼是26? –