Skip to main content
To integrate the Spam Control SDK into your Android project, follow these steps:

Adding the Repository

First, add the repository to your project’s build.gradle file:
Add the sdk as a dependency in your module’s build.gradle To always get the latest version:
To get the latest Minor and Patch versions:
Current latest version: 0.18.0

Initialization

After sync, you should be able to use the SpamControl class. It contains the following methods. Context is expected as parameter in each one. They are:
  • enableSpamControl: Turns on the service. It checks for the necessary permissions and returns a EnableReturn object that represents the synchronous result. If any permission is missing, an ui will be shown asking for it. You can listen to the result in your onActivityResult and checking the SpamControl.SpamControl_RESULT requestCode. The result code will be android.app.Activity.RESULT_OK or android.app.Activity.RESULT_CANCELED. If it is RESULT_OK, the user granted the permissions and the service is turned on. If it is RESULT_CANCELED, the user denied at least one permission and enableSpamControl should be called again. If all permissions were already granted before calling this method, the ui will not be triggered and the service will start. We expect as parameters an activity, your apiKey (which we provide) and the user’s current phoneNumber. This method requires that the user has internet connection to work. The Environment parameter defines if the service will point to Staging (STG) or Production (PROD) backend. To change Environment, the enable methods need to be called again with the new Environment (after a call to disable). It is important to notice that STG and PROD apiKeys are different. The default value for this parameter is ´PROD´. The subscriptionMode parameter defines how call blocking relates to the client’s subscription, see Subscription. The default value for this parameter is FREE.
  • enableSpamControlSilently: Turns on the service silently. It checks for the necessary permissions and returns a EnableSilentlyReturn object. If any mandatory permission is missing, the service will not be enabled. You can check by calling hasSpamControlPermissions. If all mandatory permissions were already granted before calling this method, the service will start. We expect as parameters a context, your apiKey (which we provide) and the user’s current phoneNumber. The Environment parameter defines if the service will point to Staging (STG) or Production (PROD) backend. To change Environment, the enable methods need to be called again with the new Environment (after a call to disable). It is important to notice that STG and PROD apiKeys are different. The default value for this parameter is ´PROD´. The subscriptionMode parameter works as in enableSpamControl, see Subscription.
  • disableSpamControl: Turns off the service. This method doesn’t revoke any granted permissions.
  • isSpamControlOn: Returns true if the service is on and false if it is off.
  • getCurrentEnvironment: Returns the current environment, which is an enum. Possible values are STG and PROD.
  • hasSpamControlPermissions: Returns true if the app has mandatory Spam Id permission for the service to work. Returns false if it doesn’t.
  • hasSpamControlOptionalPermissions: Returns true if the app has all of the optional permissions (READ_CONTACTS && READ_CALL_LOG). Returns false if at least one permission is missing.
  • getCalls: Returns a list of PhoneCall objects, each representing a phone call that was registered by our service. Please note that we erase objects that are considered old from time to time.
  • deleteCalls: Deletes all registered calls from our registry. Returns a DeleteCallsReturn object.
  • getUserSpamNumbers: Returns a list of UserSpamPhoneNumber objects, each representing a specific number that the user manually blocked or allowed receiving calls from.
  • blockNumber: Blocks a number. Pass the number as a trimmed number only string. Returns a BlockReturn object.
  • unblockNumber: Unblocks a number. Pass the number as a trimmed number only string. Returns a UnblockReturn object.
  • getCategories: Returns a list of Category objects, each representing a category of phone numbers that can be all blocked/unblocked at once. Only categories marked as visible should be displayed to the user.
  • blockCategory: Blocks future calls from any number inside a specific spam category
  • unblockCategory: Unblocks future calls from any number inside a specific spam category
  • isNumberBlocked: Returns a Boolean that corresponds if the number is blocked or not. It returns null only if the number is neither in the user’s call history nor among the numbers the user blocked or unblocked manually.

Subscription

The subscriptionMode parameter of enableSpamControl and enableSpamControlSilently defines how call blocking relates to the client’s subscription. It is set at activation only: when the service is already on, the parameter is ignored. The SDK keeps the subscription state up to date on its own, with its recurring syncs, so a state change reaches the device without any action from the integrator, within about 24 hours. getSubscriptionMode returns the mode in force, which is persisted across process restarts.
When the state is CANCELLED or SUBSCRIPTION_REQUIRED, the service is turned off and stays off. If a later state shows that the client subscribed again, call enableSpamControl or enableSpamControlSilently to turn it back on.
  • refreshSubscriptionState: Fetches the client’s subscription state from the backend, applies it and returns it. The SDK already refreshes the state recurrently on its own, so calling this method is optional. Call it only if you want a state change to reach the device within seconds instead of waiting for the next recurring sync, for example when the app comes to the foreground or opens from the deeplink received by SMS when the state changes. It is a suspend function, so call it from a coroutine. It is cheap and safe to call on every foreground. A timeout, a network failure or an unrecognized state leave the current state and call blocking untouched. It returns null without touching the network in FREE mode.
  • getSubscriptionState: Returns the last known SubscriptionState, without touching the network. Use PENDING_PAYMENT to decide when to show pending-payment UI. It returns null if no state was received yet. In FREE mode, the only state ever recorded is SUBSCRIPTION_REQUIRED.
  • getSubscriptionMode: Returns the current SubscriptionMode.

Migrating from 0.17.x

  • getNoPaymentStatus and setNoPaymentStatus were removed. Use getSubscriptionState() == SubscriptionState.PENDING_PAYMENT to know if blocking is suspended; the SDK owns that state now.
  • getSubscription was removed. The SDK refreshes the state on its own; use getSubscriptionState to read it and, optionally, refreshSubscriptionState to apply a change right away.
  • A device that ran the old subscription flow moves to PAID mode on update, and stays suspended if it was.

Minimum Android Version

Our current minSdkVersion is 24.

Required Permissions

The SDK will require the following permissions to function correctly:
  • INTERNET Since the block list is dynamic and needs to be downloaded from a server.
  • ACCESS_NETWORK_STATE To check if there is wifi or 4g connectivity before enabling the service.
  • READ_CONTACTS Provides access to the user’s contact list. Without this permission, it is impossible to block a call from a contact. (api 29+)
  • READ_CALL_LOG Provides access to the user’s call history. We use this data, like if a call was rejected or answered, as well as the call duration, to improve our spam detection.
  • POST_NOTIFICATIONS: So we can trigger notifications from time to time to let the user know how many blocks happened
  • Default dialer To allow the SDK to detect incoming calls (api 24 to 28).
  • Default spam app To allow the SDK to detect incoming calls (api 29+).