Skip to main content

Initialization

Get User Permission

The SDK makes network requests that include device information, including phone number. Hiya recommends waiting until the end user accepts terms and conditions before initializing the SDK.

Initialize the Hiya Service

HiyaService.register(context) must be called before calling any other API.

HiyaService.register(context)
// Alternatively, to manually enable/disable collecting analytics events pass a second boolean value. This is false
// by default on the 1 parameter function
HiyaService.register(context, true)

Enable Spam blocking

In order to block calls effectively your app will need to become the default call screener. You can request this role via the RoleManager.

// Registering for Activity result
private val requestCallScreeningRole = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {

// This API is only available on Android Q or later
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val roleManager: RoleManager = getSystemService(ROLE_SERVICE) as RoleManager

// After getting a result check to see if the role is held, if it is then you are now the default call screening app.
if (roleManager.isRoleHeld(RoleManager.ROLE_CALL_SCREENING)) {
// Handle being able to block spam
}
}
}
...

// Check if the role is available before launching the request
if (roleManager.isRoleAvailable(RoleManager.ROLE_CALL_SCREENING) {
requestCallScreeningRole.launch(roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING))
}

Enable CallerId Overlay

Your app must hold the ROLE_CALL_SCREENING role and the READ_PHONE_STATE and READ_CONTACTS permissions must be granted in order to show the callerId overlay. For more information see the Requirements page

HiyaService.startCallerIntelligence(context)
//(optional) HiyaService.showOutgoingCallerId(this.applicationContext, true)