Skip to main content

Blacklist

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:

Blacklist methods can be accessed in the following way:

val blacklistFeature = ContactManager.blacklist

Please refer to the following guide to get your account list.

Getting A List Of Accounts#

To get a list of accounts, you must follow these steps:

Reload The List Of Accounts#

Reloading the blacklist will allow you to load the actual list of accounts that are on the device:

var disposable: Disposable? = null
// ...
// This method starts background reading of the accounts from the device.// It returns Completable that completes when all accounts are collected and stored to local db.// If your app does not need to receive completion event, you don't have to subscribe// on the returned Completable - it doesn't affect the background operation.disposable = ContactManager.blackList.reload()  .observeOn(AndroidSchedulers.mainThread())  .subscribeBy(    onComplete = {      // Accounts collected successfully    },    onError = {      // Error reading accounts    }  )
// ...
// Call dispose when your app doesn't need completion event anymore.// Note that disposal does not cancel process of collecting of the accounts.disposable?.dispose()

Get A List Of Accounts#

You can get a list of accounts on the device after reloading using the observable provided by the library.

var disposable: Disposable? = null
// ...
// Returns an Observable that emits list of accounts when the accounts table changes.// You have to subscribe on returned observable in order to receive updates.disposable = ContactManager.blackList.accountListObservable  .observeOn(AndroidSchedulers.mainThread())  .subscribeBy(    onNext = { // it: List<AccountItem>!      // update your recycler view adapter      adapter.data = it    },    onError = { // it: Throwable      // do something...    }  )
// ...
// You must call dispose() on disposable that returned by subscribe() method,// when it is no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()

Account Management#

Single account management#

This method allows you to mark an account as blacklisted or exclude an account from it:

var disposable: Disposable? = null
val accountId: String = adapter.data[0].id
val enabled: Boolean = true
// ...
// Returns Completable, which completes when the data is updated to the database.// You have to subscribe on returned completable in order to receive updates.disposable = ContactManager.blackList.setAccountEnabled(accountId, enabled)  .subscribeOn(Schedulers.io())  .observeOn(AndroidSchedulers.mainThread())  .subscribeBy(    onComplete = {      // operation completed    },    onError = { // it: Throwable      // do something...    }  )
// ...
// You must call dispose() on disposable that returned by subscribe() method,// when it is no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()

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:

var disposable: Disposable? = null
val enabled: Boolean = true
// ...
// Returns Completable, which completes when the data is updated to the database.// You have to subscribe on returned completable in order to receive updates.disposable = ContactManager.blackList.setAllAccountsEnabled(enabled)  .subscribeOn(Schedulers.io())  .observeOn(AndroidSchedulers.mainThread())  .subscribeBy(    onComplete = {      // do something...    },    onError = { // it: Throwable      // do something...    }  )
// ...
// You must call dispose() on disposable that returned by subscribe() method,// when it is no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()

The Account Type#

important

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 calling the prepareToWork(), use the setAccountsEnabledByAccountType() method to ignore contacts with an account from the list:

var disposable: Disposable? = null
val enabled: Boolean = true
// ...
// Returns Completable, which completes when the data is updated to the database.// You have to subscribe on returned completable in order to receive updates.disposable = ContactManager.blackList.reload().andThen(  ContactManager.blackList.setAccountsEnabledByAccountType(    false,    appContext.resources.getStringArray(R.array.prohibited_messengers_package_list).asList()  ))  .subscribeOn(Schedulers.io())  .subscribeBy(    onComplete = {      // do something...    },    onError = { // it -> Throwable      // do something...    }  )
// ...
// You must call dispose() on disposable that returned by subscribe() method,// when it is no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()