title: What is the correct way of checking for mobile network available (no data connection)
body: <p>What is the correct way of checking if a mobile network (GSM) connection is available on Android? (>2.1) I don't want to check if there is data connection available over the mobile network just check for network availability in general. (check if phone calls over the mobile network are possible)</p>
  
  <p>At the moment I am using the following check: </p>
  
  <pre><code>public static boolean checkMobileNetworkAvailable(Context context){
      TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      int networkType = tm.getNetworkType();
      return (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN);
  }
  </code></pre>
  
  <p>But it seems that some devices always report back "NETWORK_TYPE_UNKNOWN". So the check fails all the time.</p>
  
  <p>Is there a better approach of doing it? </p>
  
  <p>Update: </p>
  
  <p>Would the following approach be better?</p>
  
  <pre><code>    public static boolean checkMobileNetworkAvailable(Context context){
         boolean isMobileNetworkAvailable = false;
         ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo[] networks = cm.getAllNetworkInfo();
         for(int i=0;i&lt;networks.length;i++){
          if(networks[i].getType() == ConnectivityManager.TYPE_MOBILE){
                if(networks[i].isAvailable()){
                  isMobileNetworkAvailable = true;
                }
              }
          }
  
      return isMobileNetworkAvailable;
  }
  </code></pre>