【问题标题】:How to check whether 3g is active or not in android如何在android中检查3g是否处于活动状态
【发布时间】:2011-11-22 14:49:44
【问题描述】:

我正在尝试检查手机中的 3G 是否处于活动状态,然后我必须触发 Intent。 所以请任何人帮助我 在此先感谢:)

【问题讨论】:

    标签: android 3g-network


    【解决方案1】:

    我最近写的一个应用程序中的另一个sn-p:

    TelephonyManager telManager;    
    telManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    int cType = telManager.getNetworkType();
    String cTypeString;
    switch (cType) {
            case 1: cTypeString = "GPRS"; break;
            case 2: cTypeString = "EDGE"; break;
            case 3: cTypeString = "UMTS"; break;
            case 8: cTypeString = "HSDPA"; break;
            case 9: cTypeString = "HSUPA"; break;
            case 10:cTypeString = "HSPA"; break;
            default:cTypeString = "unknown"; break;
    }
    

    【讨论】:

      【解决方案2】:

      试试这个东西,

          void checkConnectionStatus()
            {
             ConnectivityManager connMgr = (ConnectivityManager)
            this.getSystemService(Context.CONNECTIVITY_SERVICE);
      
      
            final android.net.NetworkInfo wifi =
            connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      
      
            final android.net.NetworkInfo mobile =
            connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
      
      
            if( wifi.isAvailable() ){
            Toast.makeText(this, "Wifi" , Toast.LENGTH_LONG).show();
            }
            else if( mobile.isAvailable() ){
            Toast.makeText(this, "Mobile 3G " , Toast.LENGTH_LONG).show();
            }
            else
            {Toast.makeText(this, "No Network " , Toast.LENGTH_LONG).show();}
            }
      }
      

      【讨论】:

        【解决方案3】:

        首先你需要检查是wifi还是移动网络

        不仅仅是打电话

        (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType());
        

        并不是说您可以使用 EDGE 或 GPRS 或其他方式,所以您也可以这样做

        if (getSsTelephony().getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS)
            return NETWORK_3G;
        

        【讨论】:

          【解决方案4】:
              ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
          
              NetworkInfo mMobile = connManager
                      .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
          
              if (mMobile.isAvailable() == true) {
                  Intent otherActivity = new Intent();
                  mapActivity.setClass(getBaseContext(), other.class);
                  startActivity(otherActivity);
              }
          

          不要忘记在 AndroidManifext.xml 文件中添加“ACCESS_NETWORK_STATE”权限!

          【讨论】:

            【解决方案5】:

            这将检查您是否有互联网连接(3G):

            private boolean isNetworkAvailable() {
                ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo activeNetworkInfo = connectivityManager
                        .getActiveNetworkInfo();
                return activeNetworkInfo != null;
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2022-01-01
              • 2020-01-11
              • 2019-12-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多