如何以编程方式(对于Android)搜索4G网络并获得结果?
更清楚的是:当我点击一个按钮时,它会搜索所有可用的4G网络,并将结果显示在列表中。
编辑:
我需要一个代码的结果和类似这样的东西:这是你在手机上搜索网络的时候。
发布于 2017-01-24 06:43:44
public String getNetworkClass(Context context) {
TelephonyManager mTelephonyManager = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = mTelephonyManager.getNetworkType();
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
return "2G";
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
return "3G";
case TelephonyManager.NETWORK_TYPE_LTE:
return "4G";
default:
return "Unknown";
}
}
Also, I would first check if connected network is WiFi or Mobile.
public static boolean getActiveNetworkType(Context context) {
boolean is_wfi_conected = false;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected() && activeNetwork.isAvailable()) { // connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to Wifi
//GET IP Address of connected WIFI
// WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
is_wfi_conected = true;
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
is_wfi_conected = false;
}
} else {
// not connected to the internet
}
return is_wfi_conected;
}https://stackoverflow.com/questions/41821403
复制相似问题