获得sim卡是几G卡
来源:互联网 发布:淘宝网小二客服电话 编辑:程序博客网 时间:2024/06/05 04:43
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.Toast;
/*
* 采用几G通道通信,通信时采用的网络类型.
* 几G的卡是移动运营商提供的移动通信通道类型,只有2G,3G。
* 获取sim卡是几G卡,步骤:
* 获得sim卡注册的移动运营商志识,获得移动运营商给sim卡提供的通信网络频段,然后判断是几G卡。
*
* 说明:
* 移动数据图标上面的E,G,H,3G网络图标不是这样判断的。通话网络和移动数据上网网络的网络类型不同
*/
* 获得移动数据通道类型
*/
public class NetworkTypeUtils {
public static final int NETWORK_TYPE_G = 0;
public static final int NETWORK_TYPE_E = 1;
public static final int NETWORK_TYPE_H = 2;
public static final int NETWORK_TYPE_3G = 3;
public static final int UNKNOWN_NETWORK_TYPE = -1;
static boolean mHspaDataDistinguishable = true;
public static int getNetworkType(Context context) {
try {
mHspaDataDistinguishable = context.getResources().getBoolean(
R.bool.config_hspa_data_distinguishable);
} catch (Exception e) {
mHspaDataDistinguishable = false;
}
TelephonyManager manager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = manager.getNetworkType();
if (networkType == TelephonyManager.NETWORK_TYPE_GPRS
|| networkType == TelephonyManager.NETWORK_TYPE_CDMA
|| networkType == TelephonyManager.NETWORK_TYPE_IDEN) {
//target = "2G";
return NETWORK_TYPE_G;
} else if (networkType == TelephonyManager.NETWORK_TYPE_EDGE
|| networkType == TelephonyManager.NETWORK_TYPE_1xRTT) {
//target = "2.75G";
return NETWORK_TYPE_E;
} else if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_0
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_A
|| networkType == TelephonyManager.NETWORK_TYPE_EVDO_B) {
//target = "3G";
return NETWORK_TYPE_3G;
} else if (networkType == TelephonyManager.NETWORK_TYPE_HSDPA
|| networkType == TelephonyManager.NETWORK_TYPE_HSUPA
|| networkType == TelephonyManager.NETWORK_TYPE_HSPA) {
if (mHspaDataDistinguishable) {
//target = "3.5G";
return NETWORK_TYPE_H;
} else {
//target = "3G";
return NETWORK_TYPE_3G;
}
} else {
//target = "未知网络";
return UNKNOWN_NETWORK_TYPE;
}
}
}
判断sim卡是几G卡的方法:
private boolean is3GSignal() {
if (serviceState != null) {
try {
String method = "getRadioTechnology";
Method mMethod = ServiceState.class.getMethod(method, null);
int networkType = (Integer) mMethod.invoke(serviceState, null);
// 由于这些静态属性都是hide注释的,所以可以通过反射来得到
Field f1 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_UMTS");
Field f2 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_HSDPA");
Field f3 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_HSUPA");
Field f4 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_HSPA");
Field f5 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_EVDO_0");
Field f6 = ServiceState.class.getDeclaredField("RADIO_TECHNOLOGY_EVDO_A");
f1.setAccessible(true);
f2.setAccessible(true);
f3.setAccessible(true);
f4.setAccessible(true);
f5.setAccessible(true);
f6.setAccessible(true);
if (networkType == f1.getInt(serviceState)
|| networkType == f2.getInt(serviceState)
|| networkType == f3.getInt(serviceState)
|| networkType == f4.getInt(serviceState)
|| networkType == f5.getInt(serviceState)
|| networkType == f6.getInt(serviceState)) {
return true;
}
Log.i("song", "3GSignal:" + networkType);
} catch(Exception e) {
e.printStackTrace();
}
}
return false;
}
- 获得sim卡是几G卡
- 如何获得SIM卡容量
- 获得SIM卡各种信息
- SIM卡信息--TelephonyManager中获得
- [SIM] MT6589 W+G/G+G dual-talk找不到SIM卡2
- [SIM] MT6589 W+G/G+G dual-talk找不到SIM卡2
- Windows mobile 从SIM卡获得手机本机号码
- 使用CoreTelephony获得SIM卡网络运营商名称
- iPhone使用CoreTelephony获得SIM卡网络运营商名称
- Android开发之获得通讯录及SIM卡中联系人
- 使用CoreTelephony获得SIM卡网络运营商名称
- 使用CoreTelephony获得SIM卡网络运营商名称
- 使用CoreTelephony获得SIM卡网络运营商名称
- 2G SIM卡中,文件返回信息简要格式
- 2G SIM卡中,文件返回信息简要格式
- 2G SIM卡中,文件返回信息简要格式
- ATT的SIM卡(GoPhone)连不上4G网络怎么办
- GSM GPRS SIM 4G 5G
- mtu
- iPad如何在短短的三年内改变世界
- oracle数字转为字符串
- 缓存溢出Buffer Overflow
- javaMain实现发送邮箱
- 获得sim卡是几G卡
- JavaSE第一百零四讲:哲学家就餐问题、死锁与使用wait及notify方法实现线程之间的相互通信
- SQL对于日期的处理
- Visual Studio 调试的一些技巧
- Gentoo服务器实现文件共享
- WordNet介绍和使用
- 新浪SAE——应用移植指南
- v6eval测试问题
- js时间比较