从电话号码查找联系人 - 旧 URI 与新 URI:旧的失败,新的成功?
我在这里阅读了相关的几个问题,但找不到答案:我有一个 Android 2.1 设备(HTC Incredible)。但是,我的应用程序必须与早期(SDK 5 之前)设备兼容,因此我使用已弃用的过滤器 URI 格式:
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
数字 的形式为 15555551212。这无法找到联系人,至少在我的设备上是这样。但是,更改为新的(SDK 5 及更高版本)ContactsContract 格式 URI
Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
会成功。最初,联系人中对应的号码格式为 +1 555 555 5555,但我将其更改为与输入号码 15555555555 完全匹配,旧格式 URI 仍然失败。在这两种情况下,新格式 URI 都会成功。
有谁有任何想法为什么会出现这种情况?我被难住了!
I've read related several questions here and can't find the answer to this: I have an Android 2.1 device (HTC Incredible). My app, however, must be compatible with early (pre SDK 5) devices, so I am using the deprecated format of filter URI:
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
The number is of the form 15555551212. This fails to find the Contact, at least on my device. However, changing to the new (SDK 5 and later) ContactsContract format URI
Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Cursor C = context.getContentResolver().query(contactUri , null, null, null, null));
results in success. Originally, the corresponding number in the Contact was in the format +1 555 555 5555, but I changed it to exactly match the input number 15555555555 and the old format URI still fails. In both cases, the new format URI succeeds.
Does anyone have any thoughts as to why this is the case? I'm stumped!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就是这样。旧的 API 根本不行。需要兼容旧设备,我使用Reflection来laod并在API >上使用新的API调用(ContactsContract) 4.
That was it. The old API just won't do. Needing to be compatible with older devices, I used Reflection to laod and use the new API calls (ContactsContract) on API > 4.