קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
באמצעות Connectivity Diagnostics API, אפליקציות שבבעלותן רשתות או שמנהלות אותן, כמו אפליקציות של ספקי סלולר, אפליקציות VPN ואפליקציות עם הצעות לרשתות Wi-Fi, יכולות לקבל מהמסגרת מידע אבחוני על קישוריות הרשת. האפליקציות האלה יכולות לרשום קריאות חוזרות ולקבל התראות עם מידע על קישוריות לרשתות שבבעלותן או בניהולן. אפליקציות לא יקבלו התראות לגבי רשתות שלא בבעלות או בניהול שלהן.
דוגמאות לאפליקציות שמנהלות רשתות או שהן בבעלות שלהן:
אפליקציות של ספקי סלולר: ניהול רשתות סלולריות שלsubId יש להן הרשאות של ספק סלולר
אפליקציות עם הצעות לרשתות Wi-Fi: רשתות Wi-Fi משלכם שהן מציעות למערכת
אפליקציות VPN: ניהול כל הרשתות שבהן ה-VPN שלהן משתמש, אבל רק כשהן ה-VPN הפעיל
קריאות חוזרות (callbacks) מופעלות במקרים הבאים:
אימות רשת: המערכת סיימה להעריך רשת ספציפית.
בכיתה ConnectivityReport מוצג מידע על המצב הנוכחי של הרשת ועל התוצאות של כל בדיקה או תהליך שבוצעו במסגרת האימות.
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;
}
דיווח על קישוריות: אפליקציה דיווחה על קישוריות למערכת דרך ConnectivityManager#reportNetworkConnectivity. הרשת והקישוריות המדווחת (בין שהאפליקציה סבורה שהרשת מספקת קישוריות ובין שלא) משותפים.
הטמעה
כדי להשתמש ב-Connectivity Diagnostics API, האפליקציה צריכה לקבל מהפלטפורמה מכונה של ConnectivityDiagnosticsManager. צריך להשתמש במכונה הזו כדי לרשום הטמעות של ConnectivityDiagnosticsCallback ולבטל את הרישום שלהן. שיטות קריאה חוזרת שלא הוגדרו מחדש הן no-ops.
בהמשך מופיעה דוגמה לרישום ולביטול רישום של ConnectivityDiagnosticsCallback:
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);
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[[["התוכן קל להבנה","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)."]]