Android Kaki

Build beautiful, usable products using required Components for Android.

Examine Ktor’s community visitors on Android with Chucker | by Yves Kalume | March 2023

When you’re engaged on an utility that interacts with the backend, you’ll undoubtedly must know if all of your requests are being executed accurately, in case of an error you will want to know the necessities as effectively. as server response for debugging.

To try this, you simply want to attach your gadget to Android studio and see the log. However the issue turned difficult when the appliance was despatched to different staff members for testing and these individuals didn’t have the mandatory abilities to debug the appliance.

Due to Chucker, you’ll be able to verify your utility’s community visitors and show the mandatory knowledge with out connecting your smartphone to your IDE.

Earlier than we begin, we have to set up all the mandatory dependencies

// ktor
// chucker

Ktor has many different dependencies, you’ll be able to even have extra relying in your wants, however since Chucker solely works with Okhttp it’s important to use Okhttp Enginethat is why we have now ktor-client-okhttp dependent.

The info generated and saved utilizing Chucker might include delicate info resembling Authorization headers or Cookies in addition to the content material of the request and response content material, it’s supposed to be used in growth and never in launch builds or different manufacturing deployments. In any other case, you do not need to remark out the code you added to make use of the Chucker earlier than constructing the discharge variant.

Chucker has a “no-op” variant of the library that enables us to decouple it from the discharge construct.

// Setting the interceptor
val chuckerInterceptor = ChuckerInterceptor.Builder(context)
// creating the Ktor HttpClienEngine
val okhttpEngine = OkHttp.create {

// creating the Ktor Shopper
val httpClient = HttpClient(okhttpEngine) {
expectSuccess = true
set up(ContentNegotiation) {
json(Json {
isLenient = true
ignoreUnknownKeys = true
prettyPrint = true

Chucker presents us ChuckerInterceptor might be added as OkHttp the interceptor will persist all these occasions inside your utility and supply a person interface to examine and share their content material.

And that is all, our requests at the moment are robotically tracked by Chucker.

// Making a request
droop enjoyable getRemoteData(): GiphyHttpResponse {
return httpClient.get("").physique()

Functions that use Chucker will show a Notification shows a abstract of ongoing HTTP exercise. Tapping the notification launches the total Chucker UI.

chucker in motion

Functions can optionally block notifications and launch the Chucker UI instantly from inside their very own interface.

Dealing with notification rights

Beginning with Android 13, your app wants to say POST_NOTIFICATION permission for the person to show the message. Since Chucker additionally shows a message to indicate community exercise, it’s worthwhile to deal with the permission request relying on the options of the appliance. With out this permission, Chucker will monitor community exercise, however there will probably be no notifications on units operating Android 13 or later.

Chucker is straightforward to make use of and really efficient in debugging when making community calls with the OkHttp consumer. To go additional, you’ll be able to try the hyperlinks beneath:

John Wick: Chapter 4 (FREE) FULLMOVIE The Super Mario Bros Movie avatar 2 Where To Watch Creed 3 Free At Home Knock at the Cabin (2023) FullMovie Where To Watch Ant-Man 3 and the Wasp: Quantumania Cocaine Bear 2023 (FullMovie) Scream 6 Full Movie

Supply hyperlink

Updated: March 28, 2023 — 6:38 am

Leave a Reply

Your email address will not be published. Required fields are marked * © 2023 Android kaki