当Android手机接电话时,如果存在于它自己的联系人数据库,呼叫会自动检查。我想知道是否有访问信息的简单方法。我有一个 PhoneStateListener
,在振铃状态进行某些操作,我要检查,如果来电者是在联系人列表中。
When an Android phone receives a call it automatically checks if the call exists in its own contact database. I was wondering if there is a simple way to access that information. I have a PhoneStateListener
that performs certain actions during a ringing state, and I want to check if the incoming caller is in the contacts list.
有没有办法做到这一点,而无需通过联系人的ContentProvider
?
Is there a way to do this without going through the Contacts ContentProvider
?
手机应用程序使用的联系人的ContentProvider
过;我不知道你为什么会想避免这种情况。此外,它的获取信息的唯一公开访问的方式。
The phone app uses the contacts ContentProvider
too; I'm not sure why you would want to avoid that. Besides, it's the only publicly-accessible way of accessing that information.
解决一个编号以一个名称(pre 2.0,在这种情况下)是很简单的反正:
Resolving a number to a name (pre 2.0, in this case) is simple enough anyway:
Uri uri = Uri.withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number));
String name = null;
Cursor cursor = context.getContentResolver().query(uri,
new String[] { Phones.DISPLAY_NAME }, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phones.DISPLAY_NAME));
cursor.close();
}