配置依赖
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
debugImplementation "com.github.ChuckerTeam.Chucker:library:3.4.0"
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:3.4.0"
}
使用 Chucker
To start using Chucker, just plug it a new ChuckerInterceptor to your OkHttp Client Builder:
val client = OkHttpClient.Builder()
.addInterceptor(ChuckerInterceptor(context))
.build()
Configure
// Create the Collector
val chuckerCollector = ChuckerCollector(
context = this,
// Toggles visibility of the push notification
showNotification = true,
// Allows to customize the retention period of collected data
retentionPeriod = RetentionManager.Period.ONE_HOUR
)
// Create the Interceptor
val chuckerInterceptor = ChuckerInterceptor(
context = this,
// The previously created Collector
collector = chuckerCollector,
// The max body content length, after this responses will be truncated.
maxContentLength = 250000L,
// List of headers to obfuscate in the Chucker UI
headersToRedact = listOf("Auth-Token"))
// Don't forget to plug the ChuckerInterceptor inside the OkHttpClient
val client = OkHttpClient.Builder()
.addInterceptor(chuckerInterceptor)
.build()
try {
// Do something risky
} catch (IOException exception) {
chuckerCollector.onError("TAG", exception)
}