🤖Android SDK
Integrating FoxHat Android
This guide will explain how to integrate FoxHat AntiSpam into your Android application .
Features
- Emulator detection
- Rooting detection
- Detection of debugging activities
- Detection of frameworks (e.g., Frida, Xposed, Shadow)
- Secure Api
Adding FoxHat to Your Project
:::info
Download FoxHat.aar
:::
Step 1: Add the .aar File to Your Project
- Copy the downloaded
.aar
file into thelibs
directory of your Android project. - Open your
build.gradle
file (usually located in theapp
module) and add the following dependency:
implementation files('libs/FoxHat.aar')
Initializing FoxHat
Once installed, the SDK needs to be configured using your Publishable Key, which can be found in the Dashboard .
:::highlight orange 📌
Emulator and Root Detection enabled by default
:::
class BaseApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize FoxHat with essential parameters
FoxHat.initialize(
this, // Application context
"your-api-key", // Replace with your actual API key
true // isProd
)
}
}
Creating tokens
The SDK generates a token, which is a required field in the Risk and Filter APIs.
:::highlight orange 📌
It's recommended that you forward the request token as a request header to every request to your API, since then you won't need to update the app whenever you're adding new server-side calls to Castle. The default value of the header is X-FoxHat-Token, but you can specify the header name in the SDK configuration.
:::
:::info[]
Token Expiration
A new token value should to be generated for each request to your backend. A request token will expire after 60 seconds and should only be used during a single request to your backend. It's recommended that you implement the token generation as a client-side middleware which generates a new request token with each request to your backend.
:::
import okhttp3.Interceptor
import okhttp3.Request
val headerInterceptor = Interceptor { chain ->
val original: Request = chain.request()
val token = FoxHat.getInstance().token().toString()
val request: Request = original.newBuilder()
.header("X-FoxHat-Token", token)
.method(original.method(), original.body())
.build()
chain.proceed(request)
}