Adding the Repository
First, add the repository to your project’sbuild.gradle file:
build.gradle
To always get the 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 aEnableReturnobject 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 youronActivityResultand checking theSpamControl.SpamControl_RESULTrequestCode. The result code will beandroid.app.Activity.RESULT_OKorandroid.app.Activity.RESULT_CANCELED. If it isRESULT_OK, the user granted the permissions and the service is turned on. If it isRESULT_CANCELED, the user denied at least one permission andenableSpamControlshould 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, yourapiKey(which we provide) and the user’s currentphoneNumber. This method requires that the user has internet connection to work. TheEnvironmentparameter defines if the service will point to Staging (STG) or Production (PROD) backend. To changeEnvironment, the enable methods need to be called again with the newEnvironment(after a call to disable). It is important to notice that STG and PRODapiKeys are different. The default value for this parameter is ´PROD´. ThesubscriptionModeparameter defines how call blocking relates to the client’s subscription, see Subscription. The default value for this parameter isFREE.
enableSpamControlSilently: Turns on the service silently. It checks for the necessary permissions and returns aEnableSilentlyReturnobject. 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, yourapiKey(which we provide) and the user’s currentphoneNumber. TheEnvironmentparameter defines if the service will point to Staging (STG) or Production (PROD) backend. To changeEnvironment, the enable methods need to be called again with the newEnvironment(after a call to disable). It is important to notice that STG and PRODapiKeys are different. The default value for this parameter is ´PROD´. ThesubscriptionModeparameter works as inenableSpamControl, 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 areSTGandPROD.
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 ofPhoneCallobjects, 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 aDeleteCallsReturnobject.
getUserSpamNumbers: Returns a list ofUserSpamPhoneNumberobjects, 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 aBlockReturnobject.
unblockNumber: Unblocks a number. Pass the number as a trimmed number only string. Returns aUnblockReturnobject.
getCategories: Returns a list ofCategoryobjects, 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
ThesubscriptionMode 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.
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 asuspendfunction, 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 returnsnullwithout touching the network inFREEmode.
getSubscriptionState: Returns the last knownSubscriptionState, without touching the network. UsePENDING_PAYMENTto decide when to show pending-payment UI. It returnsnullif no state was received yet. InFREEmode, the only state ever recorded isSUBSCRIPTION_REQUIRED.
getSubscriptionMode: Returns the currentSubscriptionMode.
Migrating from 0.17.x
getNoPaymentStatusandsetNoPaymentStatuswere removed. UsegetSubscriptionState() == SubscriptionState.PENDING_PAYMENTto know if blocking is suspended; the SDK owns that state now.getSubscriptionwas removed. The SDK refreshes the state on its own; usegetSubscriptionStateto read it and, optionally,refreshSubscriptionStateto apply a change right away.- A device that ran the old subscription flow moves to
PAIDmode on update, and stays suspended if it was.
Minimum Android Version
Our currentminSdkVersion is 24.
Required Permissions
The SDK will require the following permissions to function correctly:INTERNETSince the block list is dynamic and needs to be downloaded from a server.ACCESS_NETWORK_STATETo check if there is wifi or 4g connectivity before enabling the service.READ_CONTACTSProvides access to the user’s contact list. Without this permission, it is impossible to block a call from a contact. (api 29+)READ_CALL_LOGProvides 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+).