RSS

Posts in 2021

  • Android OkHttp change User-Agent header

    in Android

    Android OkHttp addHeader(“User-Agent”) does not work troubleshooting.

    Symptom Use OkHttpClient.Builder() to add User-Agent header. val okHttpClient = OkHttpClient.Builder() .addNetworkInterceptor { chain -> val requestBuilder = chain.request().newBuilder() .addHeader("User-Agent", userAgent) With this code, …

    Read more

  • Various ways to load PDF in Android webview

    Last Update: in Android

    Android webview can not load PDF file by default. Luckily, there are various ways to how to load PDF file in Android webview, like use google service, pdf.js etc.

    Pain point: By default, Android WebView cannot load PDF files. :( Luckily, there are various ways to how to load PDF file in Android webview. Open Intent with startActivity If your requirement does not need use embedded webview to show PDF, you can …

    Read more

  • Weird Android junit test failure java.lang.NoClassDefFoundError: android/content/Context

    in Android

    Symptom Have a Android project run junit test fine, suddenly it failed to run unit test with following error: xxxxTest initializationError java.lang.NoClassDefFoundError: android/content/Context at java.lang.Class.getDeclaredMethods0(Native Method) …

    Read more