2

In Android application, is it possible to check network availability in Interceptor. And only if the network is available, allow the request. If no network, cancel/abort the request.

Also, is it possible to get the network status without context

class ErrorInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        //Check and allow the request only if network connection is available
        val request: Request = chain.request()
        val response = chain.proceed(request)
        
        return response
    }

    private fun checkNetwork():Boolean{
       // Check network and return as per availability 
    }
}
Joseph
  • 1,060
  • 3
  • 22
  • 53

0 Answers0