Introspective
Introspective

Reputation: 736

Android Studio 2022.2.1: Network inspector data unavailable

I am using the latest & greatest Android Studio version:

Android Studio Flamingo | 2022.2.1
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023
Runtime version: 17.0.6+0-b2043.56-9586694 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0

So far, it works beautifully, but when I am trying to inspect traffic details as described in https://developer.android.com/studio/debug/network-profiler , I am getting an empty Connection View tab in the Network Inspector window:

Network inspector data unavailable

I may be missing something trivial in how I configure and operate: What do I need to do in order to view populated Connection View rows as seen in the formal documentation?

Properly populated Connection View rows

Note: The formal documentation states that

"Currently, the Network Inspector supports only the HttpsURLConnection and OkHttp libraries for network connections. If your app uses another network connection library, you might not be able to view your network activity in the Network Inspector."

How can I tell whether WebView.loadUrl() uses HttpsURLConnection and/or OkHttp?


Update: By mere chance, I managed to "catch a blip" on Network inspector due to another piece in my code using HttpURLConnection:

HttpURLConnection httpConnection = null;
try {
    URL testurl = new URL("https://www.google.com");
    URLConnection connection = testurl.openConnection();
    connection.setConnectTimeout(5 * 1000);

    httpConnection = (HttpURLConnection) connection;
    int responseCode = httpConnection.getResponseCode();
    ...
}

Connection View shows that request along with the associated data (as desired):

HttpURLConnection Connection View

So, my two questions now are:

  1. How can I tell whether WebView.loadUrl() uses HttpsURLConnection and/or OkHttp?
  2. What do I need to do in order to view populated Connection View rows for WebView.loadUrl() ?

Upvotes: 5

Views: 5572

Answers (1)

G. Putnam
G. Putnam

Reputation: 1765

This older answer appears to be the best I've found so far, that Webview "uses a snapshot of the Chrome network stack or for pre-HC devices the WebKit network stack." From marcin.kosiba's answer.

This answer provides a method for forcibly using OkHttp as the actual network stack and shouldInterceptRequest. See Michalsx's answer.

From this article, the question on Webview is not easy either, as Webview keeps getting changed by Google.

"Early versions of WebView were integrated as part of the core OS. With the release of Android 5.0, Google separated WebView from the core OS. Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. With Android 10.0, it went back to having it as a separate component."

From Developer - Managing WebView objects "Starting in Android 7.0 (API level 24), users can choose among several different packages for displaying web content in a WebView object...display web content using a particular package's implementation of WebView."

Upvotes: 3

Related Questions