Android: Why NUMBER_KEY returns the number in reverse order

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)); } 

The problem is that PhoneKey is returned in the reverse order, if the phone number is 054-123-4567, this value is 7654321450

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

thanks -Z

0
source share
1 answer

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

In any case, I suggest you not use outdated elements unless you are targeting old phones.

=================

Phone numbers are stored in separate order to facilitate matching. This helps to use the LIKE statement in SQL.

For a regular SQL user, it might look the same as in NUMBER_KEY LIKE '% 1234' and where NUMBER_KEY LIKE '4321%'. But for the db engine, having a wildcard at the end is much simpler (efficient). Efficiency is the main factor in finding an identifier for an incoming call.

By the way, you may not have noticed, most phones (not to mention only android) do not match an integer to search for the caller ID. In all Nokia phones I have a number that is stored, say, its 016 12345678 (its not a real quantity), because Mr. X When I receive a phone call from another number 016 99345678, it shows that Mr. X is calling. It compares only the last few digits !!!

+2
source

Source: https://habr.com/ru/post/974973/


All Articles