代码分为两部分:
Part One 将预置的联系人插入到数据库中;
Part Two 保证预置联系人只读,无法被编辑删除(在三个地方屏蔽对预置联系人进行编辑处理:联系人详情界面、联系人多选界面、新建联系人选择合并联系人时)。
【注意】如果您不需要限制预置联系人的删除/编辑操作,加入Part One部分代码即可,并去掉第三步”新增函数“ 中的语句:contactvalues.put(RawContacts.IS_SDN_CONTACT, -1);
Part One:
File:AbstractStartSIMService.java
Path: alps\packages\apps\Contacts\src\com\mediatek\contacts\simcontact
}
} finally {
// when this service start,but the contactsprovider has not been started yet.
// the contactCursor perhaps null, but not always.(first load will weekup the provider)
// so add null block to avoid nullpointerexception
if (contactCursor != null) {
contactCursor.close();
}
}
}//for
Log.i(TAG, "isRunningNumberCheck insert: " + sIsRunningNumberCheck);
sIsRunningNumberCheck = false;
}
}).start();
}
4.onStart中调用这个函数:
public void onStart(Intent intent, int startId) {
.....
//add by MTK---Preset Contacts
importDefaultReadonlyContact();
代码分为两部分:
Part One 将预置的联系人插入到数据库中;
Part Two 保证预置联系人只读,无法被编辑删除(在三个地方屏蔽对预置联系人进行编辑处理:联系人详情界面、联系人多选界面、新建联系人选择合并联系人时)。
【注意】如果您不需要限制预置联系人的删除/编辑操作,加入Part One部分代码即可,并去掉第一步”新增函数“ 中的语句:contactvalues.put(RawContacts.IS_SDN_CONTACT, -2);
Part One:
1.新建PresetContactsImportProcessor.java
Path: alps\packages\apps\Contacts\src\com\mediatek\contacts\simservice
package com.mediatek.contacts.simservice;
}
} finally {
// when this service start,but the contactsprovider has not been started yet.
// the contactCursor perhaps null, but not always.(first load will weekup the provider)
// so add null block to avoid nullpointerexception
if (contactCursor != null) {
contactCursor.close();
}
}//for
Log.i(TAG, "isRunningNumberCheck insert: " + sIsRunningNumberCheck);
sIsRunningNumberCheck = false;
}
}
}
2. 修改SIMServiceUtils.java
Path:alps\packages\apps\ContactsCommon\src\com\mediatek\contacts\simservice
添加
public static final int SERVICE_WORK_IMPORT_PRESET_CONTACTS = 5;
3. 修改SIMProcessorManager.java
Path:alps\packages\apps\Contacts\src\com\mediatek\contacts\simservice
在SIMProcessorManager.java中createProcessor函数里添加
else if (workType == SIMServiceUtils.SERVICE_WORK_IMPORT_PRESET_CONTACTS) {
processor = new PresetContactsImportProcessor(context, slotId, intent, listener);
}
4. 修改BootCmpReceiver.java
Path:alps\packages\apps\Contacts\src\com\mediatek\contacts\simcontact
在BootCmpReceiver.java中processBootComplete()方法最后添加代码
startSimService(-1, SIMServiceUtils.SERVICE_WORK_IMPORT_PRESET_CONTACTS);
Part Two
1. File:DefaultContactListAdapter.java
Path: alps\packages\apps\ContactsCommon\src\com\android\contacts\common\list
(1)configureOnlyShowPhoneContactsSelection函数中如下语句:
selection.append(Contacts.INDICATE_PHONE_SIM + "= ?");
selectionArgs.add("-1");
之后增加下面的代码
selection.append(" AND " + RawContacts.IS_SDN_CONTACT + " > -2");
2. File:Contact.java
Path: alps\packages\apps\ContactsCommon\src\com\android\contacts\common\model
增加如下函数:
//add by MTK---Preset Contacts
public boolean isReadOnlyContact() {
return mIsSdnContact == -2;
}
3. File:ContactLoaderFragment.java
Path:alps\packages\apps\contacts\src\com\android\contacts\detail
将isContactEditable函数修改为:
public boolean isContactEditable() {
return mContactData != null && !mContactData.isDirectoryEntry()&& !mContactData.isSdnContacts()&& !mContactData.is InternationalDialNumber()&& !mContactData.isReadOnlyContact() ;
}
4. File:ContactEntryListAdapter.java
Path:alps\packages\apps\contactscommon\src\com\android\contacts\common\list
在文件最后增加以下代码:
public boolean showReadOnlyContact = true;
public void setShowReadOnlyContact(boolean canDelete) {
showReadOnlyContact = canDelete;
}