gpt4 book ai didi

android - 获取网络类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:46:11 24 4
gpt4 key购买 nike

我一直在尝试检索当前的网络类型,但没有成功

当我说网络类型时:我指的是知道这个信息:如果类型是:NETWORK_TYPE_IDENNETWORK_TYPE_UMTS..等等..

我尝试使用:

NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo 
(ConnectivityManager.TYPE_MOBILE);

但没有成功..

我这样做是因为我想知道当前网络是否是 IDEN,或者当前网络是否通过 wifi 连接..

最佳答案

我讨厌神奇的数字:

/**
* You need to add:
*
* <pre>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
* </pre>
*
* in your AndroidManifest.xml.
*/
private String networkType() {
TelephonyManager teleMan = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
int networkType = teleMan.getNetworkType();
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_1xRTT: return "1xRTT";
case TelephonyManager.NETWORK_TYPE_CDMA: return "CDMA";
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
case TelephonyManager.NETWORK_TYPE_EHRPD: return "eHRPD";
case TelephonyManager.NETWORK_TYPE_EVDO_0: return "EVDO rev. 0";
case TelephonyManager.NETWORK_TYPE_EVDO_A: return "EVDO rev. A";
case TelephonyManager.NETWORK_TYPE_EVDO_B: return "EVDO rev. B";
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
case TelephonyManager.NETWORK_TYPE_HSDPA: return "HSDPA";
case TelephonyManager.NETWORK_TYPE_HSPA: return "HSPA";
case TelephonyManager.NETWORK_TYPE_HSPAP: return "HSPA+";
case TelephonyManager.NETWORK_TYPE_HSUPA: return "HSUPA";
case TelephonyManager.NETWORK_TYPE_IDEN: return "iDen";
case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
case TelephonyManager.NETWORK_TYPE_UNKNOWN: return "Unknown";
}
throw new RuntimeException("New type of network");
}

关于android - 获取网络类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2919414/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com