Exemple #1
0
  /**
   * Attempts to guess if the video player should show a high quality version of the video or a
   * lower bitrate version.
   *
   * @return true if it seems as though playing high-quality would be expensive or wouldn't work
   */
  public static boolean shouldShowLowQuality(Context context) {
    final ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    final NetworkInfo net = cm.getActiveNetworkInfo();

    if (metered || net == null || net.isRoaming()) {
      return true;
    }

    // this is because these devices tend to not be able to be powerful enough to show the full
    // res video
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      return true;
    }

    final int type = net.getType();

    switch (type) {
        // generally these are fast and cheap/free
      case ConnectivityManager.TYPE_WIFI:
      case ConnectivityManager.TYPE_ETHERNET:
      case ConnectivityManager.TYPE_WIMAX:
        return false;

      default:
        return true;
    }
  }
 /** @return true is device is in roaming */
 public boolean isInRoaming() {
   NetworkInfo networkInfo = mCnxManager.getActiveNetworkInfo();
   if (networkInfo != null) {
     return networkInfo.isRoaming();
   }
   return false;
 }
 /**
  * Indicates whether the device is roaming on the currently active network. When true, it suggests
  * that use of data may incur extra costs.
  */
 @CalledByNative
 private static boolean getIsRoaming(Context context) {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
   if (networkInfo == null) return false; // No active network.
   return networkInfo.isRoaming();
 }
  /** Returns true if a network connection is available and it is fast. (Ethernet or Wifi). */
  public static boolean isNetworkFast(final Context context) {
    final NetworkInfo info = getCurrentNetwork(context);
    if (info != null) {
      if (!info.isRoaming()
          && (info.getType() == ConnectivityManager.TYPE_ETHERNET
              || info.getType() == ConnectivityManager.TYPE_WIFI)) {
        return true;
      }
    }

    return false;
  }
Exemple #5
0
  public static boolean haveInternet(Context ctx) {

    NetworkInfo info =
        (NetworkInfo)
            ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();

    if (info == null || !info.isConnected()) {
      return false;
    }
    if (info.isRoaming()) {
      // here is the roaming option you can change it if you want to
      // disable internet while roaming, just return false
      return false;
    }
    return true;
  }
 private boolean checkInternetConnection() {
   boolean internetAvailable = true;
   NetworkInfo networkInfo =
       (NetworkInfo)
           ((ConnectivityManager)
                   getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE))
               .getActiveNetworkInfo();
   if (networkInfo == null) {
     internetAvailable = false;
   } else if (!networkInfo.isConnected() || networkInfo.isRoaming()) {
     internetAvailable = false;
   }
   if (!internetAvailable) {
     Intent intent = new Intent(BROADCAST_ACTION);
     intent.putExtra(PARAM_STATUS, STATUS_FINISH);
     intent.putExtra(PARAM_RESULT, getString(R.string.txt_no_internet_connection));
     sendBroadcast(intent);
   }
   return internetAvailable;
 }
  private boolean canSend() {
    boolean result = false;

    // int type = netInfo.getType();
    // int subType = netInfo.getSubType();
    // TODO change defaults based on implied speed of network

    NetworkInfo netInfo = null;
    try {
      netInfo = connectivityManager.getActiveNetworkInfo();
    } catch (SecurityException e) {
      Log.w(
          TAG,
          "Connectivity permissions have been removed from AndroidManifest.xml: " + e.getMessage());
    }
    if (netInfo != null && netInfo.isConnected() && !netInfo.isRoaming()) {
      result = true;
    }

    return result;
  }
Exemple #8
0
  private String getConnectivity() {
    ConnectivityManager conn =
        (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);

    String result = "<table>";
    result += "<tr>";
    result += "<th>DetailedState</th>";
    result += "<th>ExtraInfo</th>";
    result += "<th>Reason</th>";
    result += "<th>State</th>";
    result += "<th>Subtype</th>";
    result += "<th>Subtype name</th>";
    result += "<th>Type</th>";
    result += "<th>Type name</th>";
    result += "<th>Is connected</th>";
    result += "<th>Is connected or connecting</th>";
    result += "<th>Is failover</th>";
    result += "<th>Is roaming</th>";
    result += "</tr>\n";

    for (NetworkInfo info : conn.getAllNetworkInfo()) {
      result += "<tr>";
      result += "<td>" + info.getDetailedState() + "</td>";
      result += "<td>" + info.getExtraInfo() + "</td>";
      result += "<td>" + info.getReason() + "</td>";
      result += "<td>" + info.getState() + "</td>";
      result += "<td>" + info.getSubtype() + "</td>";
      result += "<td>" + info.getSubtypeName() + "</td>";
      result += "<td>" + info.getType() + "</td>";
      result += "<td>" + info.getTypeName() + "</td>";
      result += "<td>" + info.isConnected() + "</td>";
      result += "<td>" + info.isConnectedOrConnecting() + "</td>";
      result += "<td>" + info.isFailover() + "</td>";
      result += "<td>" + info.isRoaming() + "</td>";
      result += "</tr>\n";
    }
    result += "</table>";

    return result;
  }
  private static InterfaceDetails getInterfaceDetails(Context context) {
    InterfaceDetails ret = new InterfaceDetails();

    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();

    if (info == null || info.isConnected() == false) {
      return ret;
    }

    switch (info.getType()) {
      case ConnectivityManager.TYPE_MOBILE:
      case ConnectivityManager.TYPE_MOBILE_DUN:
      case ConnectivityManager.TYPE_MOBILE_HIPRI:
      case ConnectivityManager.TYPE_MOBILE_MMS:
      case ConnectivityManager.TYPE_MOBILE_SUPL:
      case ConnectivityManager.TYPE_WIMAX:
        ret.isRoaming = info.isRoaming();
        ret.netType = ConnectivityManager.TYPE_MOBILE;
        ret.netEnabled = true;
        break;
      case ConnectivityManager.TYPE_WIFI:
      case ConnectivityManager.TYPE_BLUETOOTH:
      case ConnectivityManager.TYPE_ETHERNET:
        ret.netType = ConnectivityManager.TYPE_WIFI;
        ret.netEnabled = true;
        break;
    }
    getTetherStatus(context, ret);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
      OldInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    } else {
      NewInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    }

    return ret;
  }
  protected int checkAvailableConnection() {
    try {
      ConnectivityManager connMgr =
          (ConnectivityManager)
              context
                  .getApplication()
                  .getAndroidApplication()
                  .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.isConnected()) {
        return ConnectivityManager.TYPE_WIFI;
      } else if (mobile.isConnected() && (!mobile.isRoaming())) {
        return ConnectivityManager.TYPE_MOBILE;
      }
    } catch (Throwable t) {
      log.warn("Caught exception when checking network status", t);
    }
    return -1;
  }
 private void access$300() {
   boolean flag = true;
   boolean flag1;
   boolean flag2;
   boolean flag3;
   boolean flag4;
   boolean flag6;
   mSyncHandler.removeMessages(2);
   ConnectivityManager connectivitymanager =
       (ConnectivityManager) mContext.getSystemService("connectivity");
   NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
   Log.d(
       "gp.PicasaSyncManager",
       (new StringBuilder("active network: ")).append(networkinfo).toString());
   if (networkinfo == null) flag1 = false;
   else
     switch (networkinfo.getType()) {
       case 0:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       case 1:
         flag6 = flag;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
       case 2:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       case 3:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       case 4:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       case 5:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       case 6:
         flag6 = false;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
       default:
         flag6 = flag;
         if (!flag6) {
           flag1 = false;
         } else {
           flag1 = flag;
         }
         break;
     }
   if (flag1 != mHasWifiConnectivity) {
     mHasWifiConnectivity = flag1;
     flag2 = flag;
   } else {
     flag2 = false;
   }
   flag3 = false;
   if (networkinfo != null) {
     boolean flag5 = networkinfo.isRoaming();
     flag3 = false;
     if (flag5) flag3 = flag;
   }
   if (flag3 != mIsRoaming) {
     mIsRoaming = flag3;
     flag2 = flag;
   }
   flag4 = connectivitymanager.getBackgroundDataSetting();
   Log.d(
       "gp.PicasaSyncManager", (new StringBuilder("background data: ")).append(flag4).toString());
   if (mBackgroundData != flag4) mBackgroundData = flag4;
   else flag = flag2;
   if (flag) updateTasksInternal();
   return;
 }