我嘗試使用2.3.4 android中的號碼獲取聯繫人的姓名,但它不工作..在這裏,我附上了我的代碼。請幫助..我已經試了很多方法如過流堆棧發佈,在模擬器它的工作,但同時手機的運行速度失敗..從Android 2.3.4號碼獲取聯繫人姓名
String[] projection = new String[] { Contacts.Phones.DISPLAY_NAME,
Contacts.Phones.NUMBER };
// encode the phone number and build the filter URI
Toast.makeText(context, "sender: "+sender, Toast.LENGTH_LONG).show();
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,
Uri.encode(sender));
// query time
Cursor c = context.getContentResolver().query(contactUri, projection, null,
null, null);
// if the query returns 1 or more results
// return the first result
if(c.getCount()>0){
if (c.moveToFirst()) {
name = c.getString(c.getColumnIndex(Contacts.Phones.DISPLAY_NAME));
}
}else{
name="UnKnown";
}
請問您可以發佈完整的代碼嗎? – swathi 2012-05-31 05:55:33