Android Configuration API
Monitor offers three configuration options for Android: Cloud (zero-config), JSON file, and Programmatic API. You can also combine them for a hybrid approach.
Configuration Options Overview
| Option | Best For | Code Required | Offline Support |
|---|---|---|---|
| Cloud (Zero-Config) | Most projects | None | No (fetches from API) |
| JSON File | Offline / auditable config | None | Yes |
| Programmatic API | Custom actions / dynamic logic | Yes | Yes |
Option A: Cloud Configuration (Zero-Config)
The simplest approach. Monitor fetches its configuration automatically from your ByteHide dashboard.
How it works:
- During build, the Gradle plugin embeds your token in the APK
- At runtime, Monitor connects to the ByteHide API
- Downloads the active configuration from your dashboard
- Applies the configured protections
- Periodically syncs for hot updates (no rebuild needed)
Setup:
Set your token as an environment variable and build:
export BYTEHIDE_API_TOKEN="your-token-here"
./gradlew assembleReleaseexport BYTEHIDE_API_TOKEN="your-token-here"
./gradlew assembleReleaseNo code changes needed. Monitor initializes automatically.
Gradle Plugin Options
You can configure the Gradle plugin in your build.gradle.kts:
bytehideMonitor {
apiToken = "your-token-here" // Or use BYTEHIDE_API_TOKEN env var
enableConfig = true // Download cloud config (default: true)
failOnLicenseError = true // Fail build on license issues (default: true)
verbose = false // Enable verbose logging (default: false)
}bytehideMonitor {
apiToken = "your-token-here" // Or use BYTEHIDE_API_TOKEN env var
enableConfig = true // Download cloud config (default: true)
failOnLicenseError = true // Fail build on license issues (default: true)
verbose = false // Enable verbose logging (default: false)
}The token is resolved in this order: explicit apiToken > BYTEHIDE_API_TOKEN environment variable > bytehide.api.token system property.
Option B: JSON Configuration
Define protections locally in a JSON file. Ideal for offline environments or when you need version-controlled configuration.
Create monitor-config.json in src/main/assets/:
{
"projectToken": "your-token-here",
"logging": {
"level": "info",
"console": true,
"file": {
"enabled": true,
"path": "logs/monitor.log"
}
},
"protections": [
{
"type": "DebuggerDetection",
"enabled": true,
"action": "close"
},
{
"type": "JailbreakDetection",
"enabled": true,
"action": "close"
},
{
"type": "EmulatorDetection",
"enabled": true,
"action": "log"
},
{
"type": "ClockTampering",
"enabled": true,
"action": "log"
},
{
"type": "MemoryDumpDetection",
"enabled": true,
"action": "close"
},
{
"type": "VirtualMachineDetection",
"enabled": true,
"action": "close"
},
{
"type": "ProcessInjection",
"enabled": true,
"action": "close"
},
{
"type": "NetworkTampering",
"enabled": true,
"action": "log"
},
{
"type": "ContainerDetection",
"enabled": true,
"action": "log"
},
{
"type": "RemoteDesktop",
"enabled": true,
"action": "log"
},
{
"type": "LicenseBinding",
"enabled": true,
"action": "close"
},
{
"type": "CloudMetadata",
"enabled": true,
"action": "log"
}
]
}{
"projectToken": "your-token-here",
"logging": {
"level": "info",
"console": true,
"file": {
"enabled": true,
"path": "logs/monitor.log"
}
},
"protections": [
{
"type": "DebuggerDetection",
"enabled": true,
"action": "close"
},
{
"type": "JailbreakDetection",
"enabled": true,
"action": "close"
},
{
"type": "EmulatorDetection",
"enabled": true,
"action": "log"
},
{
"type": "ClockTampering",
"enabled": true,
"action": "log"
},
{
"type": "MemoryDumpDetection",
"enabled": true,
"action": "close"
},
{
"type": "VirtualMachineDetection",
"enabled": true,
"action": "close"
},
{
"type": "ProcessInjection",
"enabled": true,
"action": "close"
},
{
"type": "NetworkTampering",
"enabled": true,
"action": "log"
},
{
"type": "ContainerDetection",
"enabled": true,
"action": "log"
},
{
"type": "RemoteDesktop",
"enabled": true,
"action": "log"
},
{
"type": "LicenseBinding",
"enabled": true,
"action": "close"
},
{
"type": "CloudMetadata",
"enabled": true,
"action": "log"
}
]
}Monitor loads this file automatically. No code required.
Available On-Premise Modules
See all 13 available protection modules in the Protection Modules page. All modules work on both mobile and desktop platforms.
Option C: Programmatic Configuration
Configure Monitor directly in code for maximum control, custom actions, and dynamic logic.
Kotlin
import android.app.Application
import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
import com.bytehide.monitor.core.logging.LogLevel
import android.util.Log
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Monitor.configure { config ->
// Token (optional if already embedded via Gradle)
config.useToken("bh_YourTokenHere")
// Register a custom action
config.registerCustomAction("notify") { threat ->
Log.w("ByteHideMonitor", "ALERT: ${threat.description}")
// Send notification, log to analytics, alert backend, etc.
}
// Configure logging
config.configureLogging { logging ->
logging.enableConsole()
logging.enableFileLogging("monitor.log")
logging.setMinimumLevel(LogLevel.INFO)
}
// Enable all on-premise protections with a default action
config.enableAllProtections(ActionType.CUSTOM, 60000)
// Or configure individual protections
config.addProtection(
ProtectionModuleType.DEBUGGER_DETECTION,
ActionType.CLOSE,
60000
)
config.addProtection(
ProtectionModuleType.JAILBREAK_DETECTION,
"notify", // Use custom action
60000
)
}
}
override fun onTerminate() {
super.onTerminate()
Monitor.shutdown()
}
}import android.app.Application
import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
import com.bytehide.monitor.core.logging.LogLevel
import android.util.Log
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Monitor.configure { config ->
// Token (optional if already embedded via Gradle)
config.useToken("bh_YourTokenHere")
// Register a custom action
config.registerCustomAction("notify") { threat ->
Log.w("ByteHideMonitor", "ALERT: ${threat.description}")
// Send notification, log to analytics, alert backend, etc.
}
// Configure logging
config.configureLogging { logging ->
logging.enableConsole()
logging.enableFileLogging("monitor.log")
logging.setMinimumLevel(LogLevel.INFO)
}
// Enable all on-premise protections with a default action
config.enableAllProtections(ActionType.CUSTOM, 60000)
// Or configure individual protections
config.addProtection(
ProtectionModuleType.DEBUGGER_DETECTION,
ActionType.CLOSE,
60000
)
config.addProtection(
ProtectionModuleType.JAILBREAK_DETECTION,
"notify", // Use custom action
60000
)
}
}
override fun onTerminate() {
super.onTerminate()
Monitor.shutdown()
}
}Java
import android.app.Application;
import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
import android.util.Log;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Monitor.configure(config -> {
// Token (optional if already embedded via Gradle)
config.useToken("bh_YourTokenHere");
// Register a custom action
config.registerCustomAction("notify", threat -> {
Log.w("ByteHideMonitor", "ALERT: " + threat.getDescription());
});
// Enable all on-premise protections
config.enableAllProtections(ActionType.CUSTOM, 60000);
// Or configure individual protections
config.addProtection(
ProtectionModuleType.DEBUGGER_DETECTION,
ActionType.CLOSE,
60000
);
});
}
@Override
public void onTerminate() {
super.onTerminate();
Monitor.shutdown();
}
}import android.app.Application;
import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
import android.util.Log;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Monitor.configure(config -> {
// Token (optional if already embedded via Gradle)
config.useToken("bh_YourTokenHere");
// Register a custom action
config.registerCustomAction("notify", threat -> {
Log.w("ByteHideMonitor", "ALERT: " + threat.getDescription());
});
// Enable all on-premise protections
config.enableAllProtections(ActionType.CUSTOM, 60000);
// Or configure individual protections
config.addProtection(
ProtectionModuleType.DEBUGGER_DETECTION,
ActionType.CLOSE,
60000
);
});
}
@Override
public void onTerminate() {
super.onTerminate();
Monitor.shutdown();
}
}Register your Application class in AndroidManifest.xml:
<application android:name=".MyApplication">
<!-- your activities -->
</application><application android:name=".MyApplication">
<!-- your activities -->
</application>Available Action Types
| Type | Description | Recommended Use |
|---|---|---|
| NONE | Detect only, take no action | Testing, initial analysis |
| LOG | Log the incident | Production monitoring |
| BLOCK | Block the request or operation | Cloud / web API protection |
| CLOSE | Close the application immediately | Maximum security |
| ERASE | Wipe sensitive data and close | Critical data (finance, health) |
| CUSTOM | Execute your custom handler | Business-specific logic |
Custom Action Example
config.registerCustomAction("myAction") { threat ->
// 1. Log the incident
analytics.trackSecurityThreat(threat.threatType, threat.description)
// 2. Notify the user
showSecurityWarning(threat.description)
// 3. Alert the backend
securityApi.reportThreat(threat)
// 4. Take action based on confidence
when (threat.confidence) {
in 0.8..1.0 -> {
// High confidence: close app
exitProcess(1)
}
in 0.5..0.8 -> {
// Medium confidence: limit functionality
disableSensitiveFeatures()
}
else -> {
// Low confidence: log only
Log.i("Security", "Possible threat: ${threat.description}")
}
}
}config.registerCustomAction("myAction") { threat ->
// 1. Log the incident
analytics.trackSecurityThreat(threat.threatType, threat.description)
// 2. Notify the user
showSecurityWarning(threat.description)
// 3. Alert the backend
securityApi.reportThreat(threat)
// 4. Take action based on confidence
when (threat.confidence) {
in 0.8..1.0 -> {
// High confidence: close app
exitProcess(1)
}
in 0.5..0.8 -> {
// Medium confidence: limit functionality
disableSensitiveFeatures()
}
else -> {
// Low confidence: log only
Log.i("Security", "Possible threat: ${threat.description}")
}
}
}Hybrid Configuration (Recommended for Production)
Combine cloud/JSON configuration with programmatic overrides for maximum flexibility:
Monitor.configure { config ->
// Base config is already loaded from cloud or monitor-config.json
// Override only what you need
config.registerCustomAction("criticalAlert") { threat ->
sendPushNotification("Security Alert", threat.description)
exitProcess(1)
}
// Add extra protection with custom action
config.addProtection(
ProtectionModuleType.MEMORY_DUMP_DETECTION,
"criticalAlert",
60000
)
}Monitor.configure { config ->
// Base config is already loaded from cloud or monitor-config.json
// Override only what you need
config.registerCustomAction("criticalAlert") { threat ->
sendPushNotification("Security Alert", threat.description)
exitProcess(1)
}
// Add extra protection with custom action
config.addProtection(
ProtectionModuleType.MEMORY_DUMP_DETECTION,
"criticalAlert",
60000
)
}Configuration loading order:
- Embedded encrypted configuration (injected by Gradle plugin from cloud)
- Plain
monitor-config.jsonin assets (for development / offline) - Programmatic configuration via
Monitor.configure(overrides the above)
Cloud protection modules
The Java SDK currently supports on-premise protection modules (mobile and desktop). Cloud protection modules (SQL Injection, XSS, Path Traversal, etc.) for web API monitoring will be available soon.