首页 > 代码库 > android 添加MCCMNC自动号码匹配后拨号匹配不到联系人
android 添加MCCMNC自动号码匹配后拨号匹配不到联系人
由于不同的sim卡对应不同的mccmnc, 导致min_match的值发生变化,
新的min_match值与之前phone_lookup表中保存的min_match不一直,导致无法匹配上。
修改如下:
1. 添加URI
修改ContactsProvider2.java,
private static final int PHONE_LOOKUP = 4000;
下面加入一行:
private static final int PHONE_LOOKUP2 = 4001; // New Add
matcher.addURI(ContactsContract.AUTHORITY, "provider_status", PROVIDER_STATUS);
下面加入一行:
matcher.addURI(ContactsContract.AUTHORITY, "phone_lookup2", PHONE_LOOKUP2); // New Add
2. 实现处理对应URI的方法
修改contactsProvider2.java 的 updateInTransaction().
case PHONE_LOOKUP2:
final SQLiteDatabase mDb = mDbHelper.get().getWritableDatabase(); // mDb
Cursor c = mDb.query(Tables.PHONE_LOOKUP,
new String[]{ PhoneLookupColumns.DATA_ID,
PhoneLookupColumns.RAW_CONTACT_ID,
PhoneLookupColumns.NORMALIZED_NUMBER,
PhoneLookupColumns.MIN_MATCH },
null, null, null, null, null);
while(c.moveToNext()) {
long dataId = c.getLong(0);
long rawContactId = c.getLong(1);
String normalizeNumber = c.getString(2);
String oldMinMatch = c.getString(3);
ContentValues phoneValues = new ContentValues();
phoneValues.put(PhoneLookupColumns.RAW_CONTACT_ID, rawContactId);
phoneValues.put(PhoneLookupColumns.DATA_ID, dataId);
phoneValues.put(PhoneLookupColumns.NORMALIZED_NUMBER, normalizeNumber);
// get minMatch
Log.d(TAG, "[PHONE_LOOKUP2]1.normalizeNumber:" + normalizeNumber);
String minMatch = PhoneNumberUtils.toCallerIDMinMatch(normalizeNumber);
phoneValues.put(PhoneLookupColumns.MIN_MATCH, minMatch);
Log.d(TAG, "[PHONE_LOOKUP2]2.normalizeNumber:" + normalizeNumber + " oldMinMatch:" + oldMinMatch + " minMatch:" + minMatch);
mDb.update(Tables.PHONE_LOOKUP, phoneValues, PhoneLookupColumns.DATA_ID + "=" + dataId + " AND " + PhoneLookupColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
}
c.close();
break;
3. 启动更新phone_lookup表的min_match
------------[JB 4.2]------------
修改Contacts包下的AbstractStartSIMService.java
Case FINISH_IMPORTING 这个case下面的 break 前面的 canStopSelf()之前加入如下代码:
... ...
if (canStopSelf) {
Log.i(TAG, "Will call stopSelf here.")
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
stopSelf();
}
------------[KK 4.4]------------
修改SIMProcessorManager.java,SIMProcessorManager() --> handleMessage(),
在callStopService()之前加入如下代码:
... ...
LogUtils.d(TAG, "handleMessage MSF_SEND_STOP_SERVICE");
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
callStopService();
... ...
新的min_match值与之前phone_lookup表中保存的min_match不一直,导致无法匹配上。
修改如下:
1. 添加URI
修改ContactsProvider2.java,
private static final int PHONE_LOOKUP = 4000;
下面加入一行:
private static final int PHONE_LOOKUP2 = 4001; // New Add
matcher.addURI(ContactsContract.AUTHORITY, "provider_status", PROVIDER_STATUS);
下面加入一行:
matcher.addURI(ContactsContract.AUTHORITY, "phone_lookup2", PHONE_LOOKUP2); // New Add
2. 实现处理对应URI的方法
修改contactsProvider2.java 的 updateInTransaction().
case PHONE_LOOKUP2:
final SQLiteDatabase mDb = mDbHelper.get().getWritableDatabase(); // mDb
Cursor c = mDb.query(Tables.PHONE_LOOKUP,
new String[]{ PhoneLookupColumns.DATA_ID,
PhoneLookupColumns.RAW_CONTACT_ID,
PhoneLookupColumns.NORMALIZED_NUMBER,
PhoneLookupColumns.MIN_MATCH },
null, null, null, null, null);
while(c.moveToNext()) {
long dataId = c.getLong(0);
long rawContactId = c.getLong(1);
String normalizeNumber = c.getString(2);
String oldMinMatch = c.getString(3);
ContentValues phoneValues = new ContentValues();
phoneValues.put(PhoneLookupColumns.RAW_CONTACT_ID, rawContactId);
phoneValues.put(PhoneLookupColumns.DATA_ID, dataId);
phoneValues.put(PhoneLookupColumns.NORMALIZED_NUMBER, normalizeNumber);
// get minMatch
Log.d(TAG, "[PHONE_LOOKUP2]1.normalizeNumber:" + normalizeNumber);
String minMatch = PhoneNumberUtils.toCallerIDMinMatch(normalizeNumber);
phoneValues.put(PhoneLookupColumns.MIN_MATCH, minMatch);
Log.d(TAG, "[PHONE_LOOKUP2]2.normalizeNumber:" + normalizeNumber + " oldMinMatch:" + oldMinMatch + " minMatch:" + minMatch);
mDb.update(Tables.PHONE_LOOKUP, phoneValues, PhoneLookupColumns.DATA_ID + "=" + dataId + " AND " + PhoneLookupColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
}
c.close();
break;
3. 启动更新phone_lookup表的min_match
------------[JB 4.2]------------
修改Contacts包下的AbstractStartSIMService.java
Case FINISH_IMPORTING 这个case下面的 break 前面的 canStopSelf()之前加入如下代码:
... ...
if (canStopSelf) {
Log.i(TAG, "Will call stopSelf here.")
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
stopSelf();
}
------------[KK 4.4]------------
修改SIMProcessorManager.java,SIMProcessorManager() --> handleMessage(),
在callStopService()之前加入如下代码:
... ...
LogUtils.d(TAG, "handleMessage MSF_SEND_STOP_SERVICE");
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
callStopService();
... ...
android 添加MCCMNC自动号码匹配后拨号匹配不到联系人
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。