本文整理汇总了Java中android.telephony.TelephonyManager.getNetworkType方法的典型用法代码示例。如果您正苦于以下问题:Java TelephonyManager.getNetworkType方法的具体用法?Java TelephonyManager.getNetworkType怎么用?Java TelephonyManager.getNetworkType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.TelephonyManager
的用法示例。
在下文中一共展示了TelephonyManager.getNetworkType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetworkClass
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private static int getNetworkClass(Context context) {
int networkType = NETWORK_TYPE_UNKNOWN;
try {
final NetworkInfo network = ((ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE))
.getActiveNetworkInfo();
if (network != null && network.isAvailable()
&& network.isConnected()) {
int type = network.getType();
if (type == ConnectivityManager.TYPE_WIFI) {
networkType = NETWORK_TYPE_WIFI;
} else if (type == ConnectivityManager.TYPE_MOBILE) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
networkType = telephonyManager.getNetworkType();
}
} else {
networkType = NETWORK_TYPE_UNAVAILABLE;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return getNetworkClassByType(networkType);
}
示例2: getPhoneStatus
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 获取手机状态信息
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return DeviceId(IMEI) = 99000311726612<br>
* DeviceSoftwareVersion = 00<br>
* Line1Number =<br>
* NetworkCountryIso = cn<br>
* NetworkOperator = 46003<br>
* NetworkOperatorName = 中国电信<br>
* NetworkType = 6<br>
* honeType = 2<br>
* SimCountryIso = cn<br>
* SimOperator = 46003<br>
* SimOperatorName = 中国电信<br>
* SimSerialNumber = 89860315045710604022<br>
* SimState = 5<br>
* SubscriberId(IMSI) = 460030419724900<br>
* VoiceMailNumber = *86<br>
*/
@SuppressLint("HardwareIds")
public static String getPhoneStatus() {
TelephonyManager tm = (TelephonyManager) Utils.getContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String str = "";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
str += "Line1Number = " + tm.getLine1Number() + "\n";
str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "NetworkType = " + tm.getNetworkType() + "\n";
str += "PhoneType = " + tm.getPhoneType() + "\n";
str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "SimOperator = " + tm.getSimOperator() + "\n";
str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SimState = " + tm.getSimState() + "\n";
str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
return str;
}
示例3: getPhoneStatus
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 获取手机状态信息
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return DeviceId(IMEI) = 99000311726612<br>
* DeviceSoftwareVersion = 00<br>
* Line1Number =<br>
* NetworkCountryIso = cn<br>
* NetworkOperator = 46003<br>
* NetworkOperatorName = 中国电信<br>
* NetworkType = 6<br>
* honeType = 2<br>
* SimCountryIso = cn<br>
* SimOperator = 46003<br>
* SimOperatorName = 中国电信<br>
* SimSerialNumber = 89860315045710604022<br>
* SimState = 5<br>
* SubscriberId(IMSI) = 460030419724900<br>
* VoiceMailNumber = *86<br>
*/
public static String getPhoneStatus() {
TelephonyManager tm = (TelephonyManager) Utils.getContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String str = "";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
str += "Line1Number = " + tm.getLine1Number() + "\n";
str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "NetworkType = " + tm.getNetworkType() + "\n";
str += "honeType = " + tm.getPhoneType() + "\n";
str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "SimOperator = " + tm.getSimOperator() + "\n";
str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SimState = " + tm.getSimState() + "\n";
str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
return str;
}
示例4: getDataType
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private String getDataType(Context context) {
String type = "Mobile Data";
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_HSDPA:
type = "Mobile Data 3G";
break;
case TelephonyManager.NETWORK_TYPE_HSPAP:
type = "Mobile Data 4G";
break;
case TelephonyManager.NETWORK_TYPE_GPRS:
type = "Mobile Data GPRS";
break;
case TelephonyManager.NETWORK_TYPE_EDGE:
type = "Mobile Data EDGE 2G";
break;
}
return type;
}
示例5: getPhoneStatus
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 获取手机状态信息
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
*
* @return DeviceId(IMEI) = 99000311726612<br>
* DeviceSoftwareVersion = 00<br>
* Line1Number =<br>
* NetworkCountryIso = cn<br>
* NetworkOperator = 46003<br>
* NetworkOperatorName = 中国电信<br>
* NetworkType = 6<br>
* honeType = 2<br>
* SimCountryIso = cn<br>
* SimOperator = 46003<br>
* SimOperatorName = 中国电信<br>
* SimSerialNumber = 89860315045710604022<br>
* SimState = 5<br>
* SubscriberId(IMSI) = 460030419724900<br>
* VoiceMailNumber = *86<br>
*/
@SuppressLint("HardwareIds")
public static String getPhoneStatus(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String str = "";
str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
str += "Line1Number = " + tm.getLine1Number() + "\n";
str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "NetworkType = " + tm.getNetworkType() + "\n";
str += "PhoneType = " + tm.getPhoneType() + "\n";
str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "SimOperator = " + tm.getSimOperator() + "\n";
str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SimState = " + tm.getSimState() + "\n";
str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
return str;
}
示例6: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* Whether is fast mobile network
*
* @param context
* @return
*/
private static boolean isFastMobileNetwork(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) {
return false;
}
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return false;
case TelephonyManager.NETWORK_TYPE_CDMA:
return false;
case TelephonyManager.NETWORK_TYPE_EDGE:
return false;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return true;
case TelephonyManager.NETWORK_TYPE_GPRS:
return false;
case TelephonyManager.NETWORK_TYPE_HSDPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSUPA:
return true;
case TelephonyManager.NETWORK_TYPE_UMTS:
return true;
case TelephonyManager.NETWORK_TYPE_EHRPD:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return true;
case TelephonyManager.NETWORK_TYPE_HSPAP:
return true;
case TelephonyManager.NETWORK_TYPE_IDEN:
return false;
case TelephonyManager.NETWORK_TYPE_LTE:
return true;
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return false;
default:
return false;
}
}
示例7: getDataType
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
public static String getDataType(Context activity) {
String type = "Mobile Data";
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
switch (tm.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_HSDPA:
type = "Mobile Data 3G";
Log.d("Type", "3g");
// for 3g HSDPA networktype will be return as
// per testing(real) in device with 3g enable
// data
// and speed will also matters to decide 3g network type
break;
case TelephonyManager.NETWORK_TYPE_HSPAP:
type = "Mobile Data 4G";
Log.d("Type", "4g");
// No specification for the 4g but from wiki
// i found(HSPAP used in 4g)
break;
case TelephonyManager.NETWORK_TYPE_GPRS:
type = "Mobile Data GPRS";
Log.d("Type", "GPRS");
break;
case TelephonyManager.NETWORK_TYPE_EDGE:
type = "Mobile Data EDGE 2G";
Log.d("Type", "EDGE 2g");
break;
}
return type;
}
示例8: getNetType
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 判断手机连接的网络类型(wifi,2G,3G,4G)
* 联通的3G为UMTS或HSDPA,移动和联通的2G为GPRS或EGDE,电信的2G为CDMA,电信的3G为EVDO
*/
public static int getNetType(Context context) {
int netWorkType = NETWORK_CLASS_UNKNOWN;
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
int type = networkInfo.getType();
if (type == ConnectivityManager.TYPE_WIFI) {
netWorkType = NETWORK_WIFI;
} else if (type == ConnectivityManager.TYPE_MOBILE) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
switch (telephonyManager.getNetworkType()) {
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 NETWORK_CLASS_2_G;
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 NETWORK_CLASS_3_G;
case TelephonyManager.NETWORK_TYPE_LTE:
return NETWORK_CLASS_4_G;
default:
return NETWORK_CLASS_UNKNOWN;
}
}
}
return netWorkType;
}
示例9: is4GMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private boolean is4GMobileNetwork() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService("phone");
if (telephonyManager == null) {
return false;
}
return telephonyManager.getNetworkType() == 13;
}
示例10: isWifiEnabled
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* wifi is enable
*/
public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo() != null && mgrConn
.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
示例11: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 通过TelephonyManager服务获取网络连接的网速类别
* @param context
* @return
*/
public static boolean isFastMobileNetwork(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return false; // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_CDMA:
return false; // ~ 14-64 kbps
case TelephonyManager.NETWORK_TYPE_EDGE:
return false; // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return true; // ~ 400-1000 kbps
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return true; // ~ 600-1400 kbps
case TelephonyManager.NETWORK_TYPE_GPRS:
return false; // ~ 100 kbps
case TelephonyManager.NETWORK_TYPE_HSDPA:
return true; // ~ 2-14 Mbps
case TelephonyManager.NETWORK_TYPE_HSPA:
return true; // ~ 700-1700 kbps
case TelephonyManager.NETWORK_TYPE_HSUPA:
return true; // ~ 1-23 Mbps
case TelephonyManager.NETWORK_TYPE_UMTS:
return true; // ~ 400-7000 kbps
case TelephonyManager.NETWORK_TYPE_EHRPD:
return true; // ~ 1-2 Mbps
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return true; // ~ 5 Mbps
case TelephonyManager.NETWORK_TYPE_HSPAP:
return true; // ~ 10-20 Mbps
case TelephonyManager.NETWORK_TYPE_IDEN:
return false; // ~25 kbps
case TelephonyManager.NETWORK_TYPE_LTE:
return true; // ~ 10+ Mbps
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return false;
default:
return false;
}
}
示例12: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private boolean isFastMobileNetwork() {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService("phone");
if (telephonyManager == null) {
return false;
}
switch (telephonyManager.getNetworkType()) {
case 0:
return false;
case 1:
return false;
case 2:
return false;
case 3:
return true;
case 4:
return false;
case 5:
return true;
case 6:
return true;
case 7:
return false;
case 8:
return true;
case 9:
return true;
case 10:
return true;
case 11:
return false;
case 12:
return true;
case 13:
return true;
case 14:
return true;
case 15:
return true;
default:
return false;
}
}
示例13: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private static boolean isFastMobileNetwork(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return false; // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_CDMA:
return false; // ~ 14-64 kbps
case TelephonyManager.NETWORK_TYPE_EDGE:
return false; // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return true; // ~ 400-1000 kbps
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return true; // ~ 600-1400 kbps
case TelephonyManager.NETWORK_TYPE_GPRS:
return false; // ~ 100 kbps
case TelephonyManager.NETWORK_TYPE_HSDPA:
return true; // ~ 2-14 Mbps
case TelephonyManager.NETWORK_TYPE_HSPA:
return true; // ~ 700-1700 kbps
case TelephonyManager.NETWORK_TYPE_HSUPA:
return true; // ~ 1-23 Mbps
case TelephonyManager.NETWORK_TYPE_UMTS:
return true; // ~ 400-7000 kbps
case TelephonyManager.NETWORK_TYPE_EHRPD:
return true; // ~ 1-2 Mbps
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return true; // ~ 5 Mbps
case TelephonyManager.NETWORK_TYPE_HSPAP:
return true; // ~ 10-20 Mbps
case TelephonyManager.NETWORK_TYPE_IDEN:
return false; // ~25 kbps
case TelephonyManager.NETWORK_TYPE_LTE:
return true; // ~ 10+ Mbps
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return false;
default:
return false;
}
}
示例14: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* Whether is fast mobile network
*
* @param context
* @return
*/
private static boolean isFastMobileNetwork(Context context) {
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) {
return false;
}
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return false;
case TelephonyManager.NETWORK_TYPE_CDMA:
return false;
case TelephonyManager.NETWORK_TYPE_EDGE:
return false;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return true;
case TelephonyManager.NETWORK_TYPE_GPRS:
return false;
case TelephonyManager.NETWORK_TYPE_HSDPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSUPA:
return true;
case TelephonyManager.NETWORK_TYPE_UMTS:
return true;
case TelephonyManager.NETWORK_TYPE_EHRPD:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return true;
case TelephonyManager.NETWORK_TYPE_HSPAP:
return true;
case TelephonyManager.NETWORK_TYPE_IDEN:
return false;
case TelephonyManager.NETWORK_TYPE_LTE:
return true;
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return false;
default:
return false;
}
}
示例15: isFastMobileNetwork
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* Do you have a fast mobile network?
*
* @param context context
* @return Do you have a fast mobile network? [boolean]
*/
private static boolean isFastMobileNetwork(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager == null) return false;
switch (telephonyManager.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return false;
case TelephonyManager.NETWORK_TYPE_CDMA:
return false;
case TelephonyManager.NETWORK_TYPE_EDGE:
return false;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return true;
case TelephonyManager.NETWORK_TYPE_GPRS:
return false;
case TelephonyManager.NETWORK_TYPE_HSDPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSPA:
return true;
case TelephonyManager.NETWORK_TYPE_HSUPA:
return true;
case TelephonyManager.NETWORK_TYPE_UMTS:
return true;
case TelephonyManager.NETWORK_TYPE_EHRPD:
return true;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return true;
case TelephonyManager.NETWORK_TYPE_HSPAP:
return true;
case TelephonyManager.NETWORK_TYPE_IDEN:
return false;
case TelephonyManager.NETWORK_TYPE_LTE:
return true;
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return false;
default:
return false;
}
}