您的位置:首页 > 理论基础 > 计算机网络

判断网络

2019-01-19 09:30 381 查看
  1. public static final int NETTYPE_WIFI = 0x01;
  2. public static final int NETTYPE_CMWAP = 0x02;
  3. public static final int NETTYPE_CMNET = 0x03;
  4. public int getNetworkType() {
  5. int netType = 0;
  6. ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  7. NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
  8. if (networkInfo == null) {
  9. return netType;
  10. }
  11. int nType = networkInfo.getType();
  12. if (nType == ConnectivityManager.TYPE_MOBILE) {
  13. String extraInfo = networkInfo.getExtraInfo();
  14. if(extraInfo!=null){
  15. if (extraInfo.toLowerCase().equals("cmnet")) {
  16. netType = NETTYPE_CMNET;
  17. } else {
  18. netType = NETTYPE_CMWAP;
  19. }
  20. }
  21. } else if (nType == ConnectivityManager.TYPE_WIFI) {
  22. netType = NETTYPE_WIFI;
  23. }
  24. return netType;
  25. }
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: