Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Request for new functionality
View staffing
Description
But it is not possible to get this information for other (known) networks, for example via WifiConfiguration.
I've looked through the AOSP Settings app to see how it is handled by the system and it turns out is done via android.net.NetworkPolicyManager. But you need permissions (MANAGE_NETWORK_POLICY) that are not available for non-system apps. I'd like to be able to access it.
Also see stackoverflow:
Pseudocode: (I did some serious shortcuts but I think the point will come accross)
activeNetworkIsMetered = ConnectivityManager.isActiveNetworkMetered();
if (activeNetworkIsMetered) {
// Look for better networks
wifiCfgs = WifiManager.getConfiguredNetworks();
scanResults = WifiManager.getScanResults();
for (int i=0; i<scanResults.size(); i++) {
if (wifiCfgs.contains(scanResults.get(i)) {
// configured network in range, is it metered?
if (!wifiCfgs.getByValue(scanResults.get(i)).isNetworkMetered()) {
// Better network found, connect to it
WifiManager.enableNetwork(scanResults.get(i).networkID,true);
}
}
}
}