我尝试获取可用网络列表,但当 WiFi 开启时,我只看到“WIFI”,尽管启用了 GSM/LTE。有没有获得可用网络列表的好方法?
我正在尝试这样做:
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
String strNetworkName = "";
if(null != connManager) {
Network networks[] = connManager.getAllNetworks();
if(networks != null) {
NetworkInfo nwInfo = null;
for(Network nw: networks) {
nwInfo = connManager.getNetworkInfo(nw);
strNetworkName += nwInfo.getTypeName() + ", ";
}
}
}
Toast.makeText(getApplicationContext(), strNetworkName, Toast.LENGTH_SHORT).show();