MTK_PHONE_NUMBER_GEODESCRIPTION = no //yes
2. 修改代码 CallerInfo.java:
/alps/packages/apps/InCallUI/src/com/android/incallui/CallerInfo.java
将
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
修改为:
import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import com.android.i18n.phonenumbers.NumberParseException;
import com.android.i18n.phonenumbers.PhoneNumberUtil;
import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
第二步,如果代码中的Google数据库不是最新,如何更新:
1. 现在以下Link查看最新数据有没有更正
// 中国号码对应归属地文件
// 中文版 https://github.com/googlei18n/libphonenumber/blob/master/resources/geocoding/zh/86.txt
// 英文版 https://github.com/googlei18n/libphonenumber/blob/master/resources/geocoding/en/86.txt
2. 使用以下网站最新库文件替换代码中的库文件
用这个Link下的库文件
替换代码路径下的目录下的同名文件(格式国家码_语言,如86_en , 86_cn)。
alps\external\libphonenumber\java\src\com\android\i18n\phonenumbers\geocoding\data
[DESCRIPTION]
1.拨号盘、新建联系人列表中电话栏号码格式化
2.通话记录、联系人详情界面、通话界面、来电显示电话号码格式化
3.SIM、VCard导入联系人电话号码格式化
4.禁用电话号码格式化、去掉电话号码中的空格或横杠
[NOTE]
Google Android系统中,电话号码格式化跟用户所处国家地区有关。
根据系统获得当前CountryIso,例如中国大陆是CN,美国是US,英国是UK等,按照每个国家电话号码书写习惯,格式化符合规则的号码。
例如在中国,固话格式化为“区号 xxxx xxx”或“区号 xxxx xxxx”,而手机号码格式化为“1xx xxxx xxxx”。
获得CountryIso:
Android系统当前国家码是通过接口String countryIso = GeoUtil.getCurrentCountryIso()获得。而GeoUtil.getCurrentCountryIso()一直会Call到系统服务CountryDetector,并在ComprehensiveCountryDetector.detectCountry()函数确定当前CountryIso。
系统服务CountryDetector遵循从getNetworkBasedCountry(), getLastKnownLocationBasedCountry(), getSimBasedCountry(), getLocaleCountry()顺序,其精度依次由高到低,获得系统当前最可能的CountryIso。通过查找mobilelog关键字“CountryDetector”,查看当前获得国家码。
因此,系统当前获得的CountryIso与SIM卡网络注册情况、最近一次定位位置情况、SIM发卡运营商所在地区类型、当前Android系统语言地区设置情况相关。
格式化号码:
AsYouTypeFormatter.java
(path: external\libphonenumber\java\src\com\android\i18n\phonenumbers)
通过构造函数AsYouTypeFormatter(String regionCode)传入当前CountryIso,由成员函数public String inputDigit(char nextChar)或public String inputDigitAndRememberPosition(char nextChar)依次格式化目前所输入的字符串。
[SOLUTION]
1. 拨号盘、新建联系人列表中电话栏号码格式化有问题?
(1).确认国家码是否为期望地区
(2).查看对应控件EditText是否绑定PhoneNumberFormattingTextWatcher()?
关键代码
PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(getActivity(), mDigits, mHandler);
2. 通话记录、联系人详情界面、短信列表、通话界面、来电显示电话格式化有问题?
(1).确认国家码是否为期望地区
(2).查看load数据时是否经过PhoneNumberUtils.formatNumber()函数处理。
3. SIM、VCard导入联系人电话号码格式化有问题?
(1).确认国家码是否为期望地区
(2).查看是否经AsYouTypeFormatter的inputDigit()函数处理。
4.如何禁用电话号码格式化、去掉电话号码中的空格或横杠?
(1).若想禁用EditText中的动态格式化,则修改以下文件
FILE: PhoneNumberFormatter.java
Before KK1
PATH: alps/packages/apps/contacts/src/com/android/contacts/Util
After KK1
PATH: alps/packages/apps/contactscommon/src/com/android/contacts/common/Util
---------------------------------------------------------------------------------------------------------------------------
public void afterTextChanged(Editable s) {
mSelfChanged = true;
/**不去调用父类format逻辑
*super.afterTextChanged(s);
**/
mSelfChanged = false;
}
(2).禁用TextView中号码格式化,则修改以下文件
令PhoneNumberUtils.formatNumber()方法直接返回原始号码,不会其进行格式化
FILE: PhoneNumberUtils.java
PATH: alps/frameworks/base/telephony/java/android/Telephony
-----------------------------------------------------------------------------------------------------------
public static String formatNumber(String phoneNumber, String defaultCountryIso) {
return phoneNumber; // Just return, don't format the phoneNumber
}
(3). 去掉VCard导入号码时的格式化处理代码
Before JB5
FILE: AbstractStartSIMService.java
PATH: alps/packages/apps/contacts/src/com/mediatek/contacts/Simcontact
After JB5
FILE: SIMImportProcessor.java
PATH: alps/packages/apps/contacts/src/com/mediatek/contacts/simservice
(1) 去掉 actuallyImportOneSimContact() 方法中对 phoneNumber 的格式化处理代码 :
/*
* Bug Fix by Mediatek Begin. Original Android's code: xxx
* CR ID: ALPS00289127 Descriptions:
*/
Log.i(TAG, "[actuallyImportOneSimContact] phoneNumber before : " + phoneNumber);
// AsYouTypeFormatter mFormatter = PhoneNumberUtil.getInstance()
// .getAsYouTypeFormatter(countryCode);
// char[] cha = phoneNumber.toCharArray();
// int ii = cha.length;
// for (int num = 0; num < ii; num++) {
// phoneNumber = mFormatter.inputDigit(cha[num]);
// }
Log.i(TAG, "[actuallyImportOneSimContact] phoneNumber after : " + phoneNumber);
/*
* Bug Fix by Mediatek End.
*/
(2) 去掉 actuallyImportOneSimContact() 方法中对 additionalNumber 的格式化处理代码:
/*
* Bug Fix by Mediatek Begin. Original Android's code:
* xxx CR ID: ALPS00289127 Descriptions:
*/
Log.i(TAG, "[actuallyImportOneSimContact] additionalNumber before : "
+ additionalNumber);
// AsYouTypeFormatter mFormatter = PhoneNumberUtil.getInstance()
// .getAsYouTypeFormatter(countryCode);
// char[] cha = additionalNumber.toCharArray();
// int ii = cha.length;
// for (int num = 0; num < ii; num++) {
// additionalNumber = mFormatter.inputDigit(cha[num]);
// }
Log.i(TAG, "[actuallyImportOneSimContact] additionalNumber after : "
+ additionalNumber);
/*
* Bug Fix by Mediatek End.
*/
FILE: PhoneNumberFormatter.java
PATH: alps/packages/apps/contacts/src/com/android/contacts/Util
PATH: alps/packages/apps/contactscommon/src/com/android/contacts/common/Util
---------------------------------------------------------------------------------------------------------------------------
public void afterTextChanged(Editable s) {
mSelfChanged = true;
/**不去调用父类format逻辑
*super.afterTextChanged(s);
**/
mSelfChanged = false;
}
FILE: PhoneNumberUtils.java
PATH: alps/frameworks/base/telephony/java/android/Telephony
---------------------------------------------------------------------------------------------------------------------------
/**
* Format a phone number.
* <p>
* If the given number doesn't have the country code, the phone will be
* formatted to the default country's convention.
*
* @param phoneNumber
* the number to be formatted.
* @param defaultCountryIso
* the ISO 3166-1 two letters country code whose convention will
* be used if the given number doesn't have the country code.
* @return the formatted number, or null if the given number is not valid.
*
* @hide
*/
public static String formatNumber(String phoneNumber, String defaultCountryIso) {
// Before modified
// // Do not attempt to format numbers that start with a hash or star symbol.
// if (phoneNumber.startsWith("#") || phoneNumber.startsWith("*")) {
// return phoneNumber;
// }
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
// String result = null;
// try {
// PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso);
// result = util.formatInOriginalFormat(pn, defaultCountryIso);
// } catch (NumberParseException e) {
// }
// return result;
// After modified
return phoneNumber; // Just return, don't format the phoneNumber
}
PATH: alps/packages/apps/contacts/src/com/mediatek/contacts/Simcontact
PATH: alps/packages/apps/contacts/src/com/mediatek/contacts/simservice
---------------------------------------------------------------------------------------------------------------------------
/*
* Bug Fix by Mediatek Begin. Original Android's code: xxx
* CR ID: ALPS00289127 Descriptions:
*/
Log.i(TAG, "[actuallyImportOneSimContact] phoneNumber before : " + phoneNumber);
// AsYouTypeFormatter mFormatter = PhoneNumberUtil.getInstance()
// .getAsYouTypeFormatter(countryCode);
// char[] cha = phoneNumber.toCharArray();
// int ii = cha.length;
// for (int num = 0; num < ii; num++) {
// phoneNumber = mFormatter.inputDigit(cha[num]);
// }
Log.i(TAG, "[actuallyImportOneSimContact] phoneNumber after : " + phoneNumber);
/*
* Bug Fix by Mediatek End.
*/
---------------------------------------------------------------------------------------------------------------------------
/*
* Bug Fix by Mediatek Begin. Original Android's code:
* xxx CR ID: ALPS00289127 Descriptions:
*/
Log.i(TAG, "[actuallyImportOneSimContact] additionalNumber before : "
+ additionalNumber);
// AsYouTypeFormatter mFormatter = PhoneNumberUtil.getInstance()
// .getAsYouTypeFormatter(countryCode);
// char[] cha = additionalNumber.toCharArray();
// int ii = cha.length;
// for (int num = 0; num < ii; num++) {
// additionalNumber = mFormatter.inputDigit(cha[num]);
// }
Log.i(TAG, "[actuallyImportOneSimContact] additionalNumber after : "
+ additionalNumber);
/*
* Bug Fix by Mediatek End.
*/
修改下面这行:
return mDialerSearchSupport.handleDialerSearchQueryEx(db,uri);
为:
return mDialerSearchSupport.handleDialerSearchQueryEx2(db,uri);
然后添加下面的代码:
2. 添加如下包
在DialerSearchSupport.java文件开头加入:
import android.database.MergeCursor;
3. 添加函数:
public Cursor handleDialerSearchQueryEx2(SQLiteDatabase db, Uri uri) {
String filterParam = uri.getLastPathSegment();
if(filterParam.startsWith("0") || filterParam.startsWith("+44")){
String filterParam2 = null;
Cursor[] cursors = new Cursor[2];
if(filterParam.startsWith("0"))
filterParam2 = "+44" + filterParam.substring(1);
else if(filterParam.startsWith("+44"))
filterParam2 = "0" + filterParam.substring(3);
LogUtils.d(TAG, "MTK-DialerSearch, filterParam: " +filterParam+"filterParam2: "+filterParam2);
cursors[0]= handleDialerSearchQueryEx(db, uri,filterParam);
LogUtils.d(TAG, "MTK-DialerSearch, queryDialerSearch, end.1. ResultCount:cursors[0]=" + cursors[0].getCount());
cursors[1]= handleDialerSearchQueryEx(db, uri,filterParam2);
LogUtils.d(TAG, "MTK-DialerSearch, queryDialerSearch, end.2. ResultCount:cursors[1]=" + cursors[1].getCount());
return new MergeCursor(cursors);
} else {
Cursor c = handleDialerSearchQueryEx(db,uri, filterParam);
LogUtils.d(TAG, "MTK-DialerSearch, queryDialerSearch, end. ResultCount: " + c.getCount());
return c;
}
}
3. 将 public Cursor handleDialerSearchQueryEx(SQLiteDatabase db, Uri uri)
这个函数头修改为:
public Cursor handleDialerSearchQueryEx(SQLiteDatabase db, Uri uri,String filterParam)
String filterParam = uri.getLastPathSegment();