public class ConnectivityReport {
Network network;
long reportTimestamp;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle additionalInfo;
}
สงสัยว่าข้อมูลหยุดชะงัก: สงสัยว่าข้อมูลหยุดชะงัก ซึ่งเป็นเงื่อนไขที่แพ็กเก็ต IP ไม่ได้ส่งผ่านเครือข่ายอย่างถูกต้อง คลาส DataStallReport จะแสดงข้อมูลเกี่ยวกับการหยุดทำงานของข้อมูลที่สงสัย
public class DataStallReport {
Network network;
long reportTimestamp;
int detectionMethod;
LinkProperties linkProperties;
NetworkCapabilities networkCapabilities;
PersistableBundle stallDetails;
}
NetworkRequestrequest=newNetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();// Use an Executor that is appropriate for your use caseExecutorexecutor=Executors.newSingleThreadExecutor();ConnectivityDiagnosticsManagercdm=context.getSystemService(ConnectivityDiagnosticsManager.class);ExampleCallbackcallback=newExampleCallback();cdm.registerConnectivityDiagnosticsCallback(request,executor,callback);...// Collect connectivity information on networks that match with request...cdm.unregisterConnectivityDiagnosticsCallback(callback);
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# Connectivity Diagnostics API\n\nThe Connectivity Diagnostics API allows apps that own or manage networks, such\nas carrier apps, VPN apps, and Wi-Fi suggestion apps, to receive diagnostic\nnetwork connectivity information from the framework. These apps can register\ncallbacks and receive notifications with connectivity information for the\nnetworks that they own or manage. Apps won't receive notifications for networks\nthat aren't owned or managed by the app.\n\nThe following are examples of apps that manage or own networks:\n\n- **Carrier apps:** Manage cellular networks for which their `subId` has carrier privileges for\n- **Wi-Fi suggestion apps:** Own Wi-Fi networks that they suggest to the system\n- **VPN apps:** Manage all networks that their VPN uses, but only when they are the active VPN\n\nCallbacks are invoked in the following cases:\n\n- **Network validation:** The system finished evaluating a specific network.\n The\n [`ConnectivityReport`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityReport)\n class provides information on the current state of the network and the\n results of any tests or procedures performed as part of the validation.\n\n public class ConnectivityReport {\n Network network;\n long reportTimestamp;\n LinkProperties linkProperties;\n NetworkCapabilities networkCapabilities;\n PersistableBundle additionalInfo;\n }\n\n- **Data stall suspected:** A data stall, a condition in which IP packets\n aren't properly flowing through the network, is suspected. The\n [`DataStallReport`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.DataStallReport)\n class provides information about suspected data stalls.\n\n public class DataStallReport {\n Network network;\n long reportTimestamp;\n int detectionMethod;\n LinkProperties linkProperties;\n NetworkCapabilities networkCapabilities;\n PersistableBundle stallDetails;\n }\n\n- **Connectivity reported:** An app has reported connectivity through\n [`ConnectivityManager#reportNetworkConnectivity`](https://developer.android.com/reference/android/net/ConnectivityManager#reportNetworkConnectivity(android.net.Network,%20boolean))\n to the system. The network and reported connectivity (whether the app\n believes the network does or doesn't provide connectivity) is shared.\n\nImplementation\n--------------\n\n| **Note:** Apps registering callbacks must have the [`ACCESS_FINE_LOCATION`](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION) permission because connecting to location-specific networks can expose the fine location of the user.\n\nTo use the Connectivity Diagnostics API, an app must obtain a\n[`ConnectivityDiagnosticsManager`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager)\ninstance from the platform. This instance should be used to register and\nunregister\n[`ConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)\nimplementations. Callback methods that aren't overridden are no-ops.\n\nBelow is an example of a\n[`ConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)\nimplementation: \n\n public class ExampleCallback extends ConnectivityDiagnosticsCallback {\n @Override\n public void onConnectivityReportAvailable(@NonNull ConnectivityReport report) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n\n @Override\n public void onDataStallSuspected(@NonNull DataStallReport report) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n\n @Override\n public void onNetworkConnectivityReported(\n @NonNull Network network, boolean hasConnectivity) {\n ... \n // Log data, take action based on report result, etc\n ... \n }\n }\n\nTo register callbacks and receive notifications, call\n[`registerConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager#registerConnectivityDiagnosticsCallback(android.net.NetworkRequest,%20java.util.concurrent.Executor,%20android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)).\nTo unregister callbacks and stop receiving notifications, call\n[`unregisterConnectivityDiagnosticsCallback`](https://developer.android.com/reference/android/net/ConnectivityDiagnosticsManager#unregisterConnectivityDiagnosticsCallback(android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback)).\n| **Note:** The callbacks must be registered and unregistered using the same [`uid`](https://developer.android.com/reference/android/content/pm/ApplicationInfo.html#uid).\n\nBelow is an example for registering and unregistering\n`ConnectivityDiagnosticsCallback`: \n\n NetworkRequest request =\n new NetworkRequest.Builder()\n .addTransportType(TRANSPORT_CELLULAR)\n .build();\n // Use an Executor that is appropriate for your use case\n Executor executor = Executors.newSingleThreadExecutor();\n\n ConnectivityDiagnosticsManager cdm =\n context.getSystemService(ConnectivityDiagnosticsManager.class);\n\n ExampleCallback callback = new ExampleCallback();\n cdm.registerConnectivityDiagnosticsCallback(\n request, executor, callback);\n\n ... \n // Collect connectivity information on networks that match with request\n ... \n\n cdm.unregisterConnectivityDiagnosticsCallback(callback);\n\nValidation\n----------\n\nThe Connectivity Diagnostics API is CTS tested by\n[`ConnectivityDiagnosticsManagerTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Connectivity/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java)."]]