Package-level declarations
Black List
Black List
The blacklist is designed to restrict the list of contacts retrieved from the device. Contacts belonging to an account or account type from the blacklist do not participate in the process of updating the contact list on the server.
There are two ways to replenish the blacklist:
Specify the id of the account whose contacts you want to exclude from the update process
Specify the type of accounts whose contacts you want to exclude from the update process
Blacklist methods can be accessed in the following way:
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackListGetting A List Of Accounts
To get a list of accounts, you must follow these steps:
Reload the list of accounts on the device
Get a list of accounts from the library
Reload The List Of Accounts
Reloading the blacklist will allow you to load the actual list of accounts that are on the device:
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackList
// This method starts background reading of the accounts from the device.
// It returns Job that completes when all accounts are collected and stored to local db.
val fetchAccountsJob: Job = blackList.fetchAccounts()
fetchAccountsJob.join()Get A List Of Accounts
You can get a list of accounts on the device after reloading using the flow provided by the library.
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackList
lifecycleScope.launch {
blackList.accountsFlow.collect { accounts -> // accounts: List<AccountItem>
// Handle it...
}
}Account Management
Single account management
This method allows you to mark an account as blacklisted or exclude an account from it:
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackList
lifecycleScope.launch {
blackList.setAccountEnabled("accountId", true)
}Manage All Accounts
For user convenience, applications can provide the ability to enable or disable all accounts at once (for example, the user disables all accounts, and then enables only some of them). Since the operation on an account is performed in the background and may take some time, consecutive disconnection of all accounts one by one (for example, in a loop) is ineffective. For such cases, it is recommended to use the ContactManager.blackList.setAllAccountsEnabled(enable) function.
Sample code of enabling all accounts:
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackList
lifecycleScope.launch {
blackList.setAllAccountsEnabled(true)
}The Account Type
By using the backup / restore of contacts, if various messengers are installed on the device, duplicate contacts are mistakenly created. To solve this problem, we strongly recommend blocking the following account types by package name:
com.viber.voip
org.telegram.messenger
org.telegram.plus
com.twitter.android
com.yandex.yamb
com.facebook.orca
com.skype.raider
com.whatsapp
com.whatsapp.w4b
ru.ok.messages
com.snapchat.android
com.imo.android.imoim
com.tencent.mm
com.icq.mobile.client
org.thoughtcrime.securesms
org.telegram.plus
org.thunderdog.challegram
For convenience, create a config.xml file in your android project to store the list of account types that you want to add to the blacklist.
<resources>
// ...
<string-array name="prohibited_messengers_package_list">
<item>com.viber.voip</item>
<item>org.telegram.messenger</item>
<item>com.twitter.android</item>
<item>com.yandex.yamb</item>
<item>com.facebook.orca</item>
<item>com.skype.raider</item>
<item>com.whatsapp</item>
<item>com.whatsapp.w4b</item>
<item>ru.ok.messages</item>
<item>com.snapchat.android</item>
<item>com.imo.android.imoim</item>
<item>com.tencent.mm</item>
<item>com.icq.mobile.client</item>
<item>org.thoughtcrime.securesms</item>
<item>org.telegram.plus</item>
<item>org.thunderdog.challegram</item>
</string-array>
// ...
<resources/>Then, after session started, use the setAccountsEnabledByTypes() method to ignore contacts with an account from the list:
val contactManager: ContactManager
val blackList: BlackListManager = contactManager.blackList
lifecycleScope.launch {
blackList.setAccountsEnabledByTypes(
isEnabled = true,
accountTypes = appContext.resources.getStringArray(R.array.prohibited_messengers_package_list).asList().toSet()
)
}