安卓:为什么NUMBER_KEY返回逆序数 [英] Android : Why NUMBER_KEY return the number in reverse order

查看:121
本文介绍了安卓:为什么NUMBER_KEY返回逆序数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的code读取联系人列表:

I am trying to read the contact list using the following code:

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(People.CONTENT_URI,null, null, null, null);
if (cur.getCount() > 0) {

while (cur.moveToNext()) 
{ 
   String id = cur.getString(cur.getColumnIndex(People._ID));
       Cursor personCur = cr.query(Contacts.Phones.CONTENT_URI, 
                null, 
                Contacts.Phones.PERSON_ID +"= ?"+                                     Contacts.Phones.NUMBER_KEY , 
                    new String[]{id}, null);

            String phoneKey = "";
            while (personCur.moveToNext()) {
                phoneKey = personCur.getString(personCur.getColumnIndex(Contacts.Phones.NUMBER_KEY));

            } 

问题是按照相反的顺序含义phoneKey回报如果电话号码是054-123-4567值为7654321450

The problem is that phoneKey return in reverse order meaning if the phone number is 054-123-4567 the value is 7654321450

我找不到任何关于此问题的文档。
不知道如何解决它?或者是预期的结果?

I could not find any documentation on this issue. Any idea how to fix it? or is it the expected result?

谢谢
-Z

推荐答案

首先,Contacts.Phones.NUMBER_KEY是pcated德$ P $。
其次,为什么还需要这个价值?这不是电话号码,但正常化的电话号码。
如果你想在你有你的code方式的电话号码,使用Contacts.Phones.NUMBER

Firstly, Contacts.Phones.NUMBER_KEY is deprecated. Secondly, why do you need this value? This is not the phone number, but the "normalized" phone number. If you want the phone number in the way you have your code, use Contacts.Phones.NUMBER

不管怎样,我建议你不要使用去precated元素,除非你是针对老年手机。

Anyways, I would suggest you not to use deprecated elements unless you are targeting older phones.

=====

电话号码存储在剥离颠倒以便更容易匹配。它有助于使用LIKE运算符的SQL。

Phone numbers are stored in stripped reversed order for easier matching. It helps to use the LIKE operator in SQL.

对于一个正常的SQL用户,它可能看起来相同的使用,其中NUMBER_KEY LIKE'%1234'何NUMBER_KEY LIKE'%4321'。
但对于数据库引擎,其一端通配符要容易得多(高效的)效率是呼入来电显示查找的主要因素。

For a normal SQL user, it might look same to use where NUMBER_KEY LIKE '%1234' and where NUMBER_KEY LIKE '4321%'. But for the db engine, having the wildcard at the end is much easier (efficient) Efficiency is a major factor for incoming call caller id lookup.

顺便说一句,你可能没有注意到,大多数手机(不谈论机器人只)不匹配来电显示查找整个号码。
在我所有的诺基亚手机,我有许多保存,它说016 12345678(它不是实数)作为X先生
当我从另一个号码016 99345678打来电话,这说明X先生呼吁。它比较只剩下最后几个数字!

BTW, you might have not noticed, most phones (not talking about android only) does not match the whole number for caller id lookup. In all my Nokia phones I have a number saved, say its 016 12345678 (its not the real number) as Mr X When I get phone call from another number 016 99345678, it shows Mr X is calling. It compares only last few digits!!!

这篇关于安卓:为什么NUMBER_KEY返回逆序数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆