A method in Android programming where Numbers match digit modifications

  • 2020-10-23 21:12:39
  • OfStack

This article illustrates the method of number matching digit modification in Android programming. To share for your reference, the details are as follows:

The default number matching digit on Android2.1 is 7 bits, that is, from right to left, if 7 bits of two Numbers are matched, then they are considered to be the same number. For example, +86 1234567 and 01234567 are the same number. So to determine whether two Numbers match, simply using "==" is not acceptable.

Android in phone_numbers_equal Sqlite layer added function is used to number matching judgment, this function is the database level, the corresponding SQL statement is PHONE_NUMBERS_EQUAL, android will this function in the form of two and three parameters to register sqlite database, the situation of the two parameters is number A and number B, three parameters are more a bool variables, used to indicate whether or not to use strictly match, the strict match is specially used to Thailand, It seems that Thailand has a special number rule, while in our country, this variable 1 is usually 0.

It is easy to change the number matching digit of android to the desired number in the OldPhoneNumberUtils.cpp file. This number is used in the function phone_number_compare_loose function, which is actually the actual function of number matching, file location: external\sqlite\android


static int MIN_MATCH = 7; 
// Change it to the number you want 

There is also a sample java function implementation at the framwork layer, compareLoosely (A,B), framewoeks\base\telephony\ android\telephony\ PhoneNumberUtils.java, where the MIN_MATCH used also needs to be modified.

[Note] : 2.1 phone_number_compare_loose and compareLoosely function implementation there are a few lines of code, is BUG, will affect the English state 6-bit length of the number matching

I hope this article has been helpful in Android programming.


Related articles: