Connection View: アプリの CPU スレッド全体での、タイムライン選択部分で送受信されたファイルをリストします。リクエストごとにサイズ、種類、ステータス、送信期間を調べることができます。列の見出しのいずれかをクリックすると、リストを並べ替えることができます。また、タイムラインの選択部分に関する詳細な分析情報が表示され、各ファイルが送受信されたタイミングが表示されます。
Thread View: アプリの各 CPU スレッドのネットワーク アクティビティを表示します。図 2 に示すように、このビューでは各ネットワーク リクエストがどのスレッドによるものなのかを調査できます。
HttpsURLConnection API を使用している場合、次のサンプルに示すように setRequestProperty メソッドを使用してコードに含めた [Request] タブにのみヘッダーが表示されます。
Kotlin
valurl=URL(MY_URL_EN)valurlConnection:HttpsURLConnection=url.openConnection()asHttpsURLConnection...// Sets acceptable encodings in the request header.urlConnection.setRequestProperty("Accept-Encoding","identity")
Java
URLurl=newURL(MY_URL_EN);HttpsURLConnectionurlConnection=(HttpsURLConnection)url.openConnection();//...// Sets acceptable encodings in the request header.urlConnection.setRequestProperty("Accept-Encoding","identity");
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Inspect network traffic with the Network Inspector\n\nThe Network Inspector displays real-time network activity on a timeline, showing\ndata sent and received. The Network Inspector lets you examine how and when your\napp transfers data and optimize the underlying code appropriately.\n\nTo open the Network Inspector, follow these steps:\n\n1. From the Android Studio navigation bar, select **View \\\u003e** **Tool Windows \\\u003e** **App Inspection** . After the app inspection window automatically connects to an app process, select **Network Inspector** from the tabs.\n - If the app inspection window doesn't connect to an app process automatically, you may need to select an app process manually.\n2. Select the device and app process you want to inspect from the **App Inspection** window.\n\nNetwork Inspector overview\n--------------------------\n\nAt the top of the Network Inspector window, you can see the event timeline.\nClick and drag to select a portion of the timeline and inspect the traffic.\n**Figure 1.** The Network Inspector window.\n\nIn the details pane, the timing graph can help you identify where performance\nissues could be occurring. The start of the yellow section corresponds to the\nfirst byte of the request being sent. The start of the blue section corresponds\nto the first byte of the response being received. The end of the blue section\ncorresponds to the final byte of the response being received.\n\nIn the pane below the timeline, select one of\nthe following tabs for more detail about the network activity during the\nselected portion of the timeline:\n\n- **Connection View**: Lists files that were sent or received during the selected portion of the timeline across all of your app's CPU threads. For each request, you can inspect the size, type, status, and transmission duration. To sort this list, click any of the column headers. You can also see a detailed breakdown of the selected portion of the timeline, showing when each file was sent or received.\n- **Thread View**: Displays the network activity on each of your app's CPU\n threads. As shown in figure 2, this view lets you inspect which\n threads are responsible for each network request.\n\n **Figure 2.** Inspect network requests by app thread in the **Thread View**.\n- **Rules View** : Rules help test how your app behaves when encountering\n responses with different status codes, headers, and bodies. When you create a\n new rule, name your new rule and include information about the origin of the\n response you want to intercept under the **Origin** subsection. In the\n **Response** subsection, you can specify where and how to modify the\n response. For example, you can set the rule to execute on responses with a\n specific status code as well as modify that status code. In the\n **Header rules** and **Body rules** subsections, create sub-rules that add or\n modify response headers or bodies. Rules are applied in the order that\n they're listed. Choose which rule to enable or disable by checking the\n **Active** box next to the rule.\n\n **Figure 3.** Network Inspector **Rules** and **Rule Details** panes.\n\nFrom either the **Connection View** or **Thread View**, click a request name to\ninspect detailed information about the data sent or received. Click the tabs to\nview the response header and body, request header and body, or call stack.\n\nOn the **Response** and **Request** tabs, click the **View Parsed** link to\ndisplay formatted text. Click the **View Source** link to display raw text.\n**Figure 4.** Toggle between raw text and formatted text by clicking the corresponding link.\n\nIn addition to showing network requests for\n[`HttpsURLConnection`](/reference/javax/net/ssl/HttpsURLConnection), Network\nInspector also supports [`OkHttp`](http://square.github.io/okhttp).\nSome third-party network libraries, such as\n[Retrofit](https://square.github.io/retrofit/), use `OkHttp`\ninternally, so Network Inspector lets you inspect their network activity. The\n[Now In Android sample app](https://github.com/android/nowinandroid)\nuses `OkHttp` for its network operations and is a good place to see it in\naction.\n\nIf you are using the\n`HttpsURLConnection` API,\nyou only see headers in the **Request** tab that you include in your code using\nthe\n[`setRequestProperty`](/reference/java/net/URLConnection#setRequestProperty(java.lang.String,%20java.lang.String))\nmethod, as shown in the following sample: \n\n### Kotlin\n\n```kotlin\nval url = URL(MY_URL_EN)\nval urlConnection: HttpsURLConnection = url.openConnection() as HttpsURLConnection\n...\n// Sets acceptable encodings in the request header.\nurlConnection.setRequestProperty(\"Accept-Encoding\", \"identity\")\n```\n\n### Java\n\n```java\nURL url = new URL(MY_URL_EN);\nHttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();\n//...\n// Sets acceptable encodings in the request header.\nurlConnection.setRequestProperty(\"Accept-Encoding\", \"identity\");\n```\n\nTroubleshoot network connection\n-------------------------------\n\nIf the Network Inspector detects traffic values but can't identify any\nsupported network requests, you receive the following error message: \n\n **Network Inspector Data Unavailable:** There is no information for the\n network traffic you've selected.\n\nCurrently, the Network Inspector supports only the\n[`HttpsURLConnection`](/reference/javax/net/ssl/HttpsURLConnection)\nand [`OkHttp`](http://square.github.io/okhttp) libraries for network\nconnections. If your app uses another network connection library, you might not\nbe able to view your network activity in the Network Inspector. If you have\nreceived this error message but your app does use `HttpsURLConnection`\nor `OkHttp`, [report a bug](/studio/report-bugs) or\n[search the issue\ntracker](https://issuetracker.google.com/issues?q=componentid:317727%2B)\nto include your feedback in an existing report related to your issue. You\ncan also use these resources to request support for additional libraries."]]