Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been using a small setup to check the bandwidth for determining how to scale things, such as images.</p> <p>Under the activity, in AndroidManifest:</p> <pre><code>&lt;intent-filter&gt; ... &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE"/&gt; &lt;/intent-filter&gt; </code></pre> <p>In the activity where the checks are being performed:</p> <pre><code>boolean network; int bandwidth; @Override public void onCreate(Bundle savedInstanceState) { ... network = isDataConnected(); bandwidth = isHighBandwidth(); registerReceiver(new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { network = isDataConnected(); bandwidth = isHighBandwidth(); } }, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); ... } ... private boolean isDataConnected() { try { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo().isConnectedOrConnecting(); } catch (Exception e) { return false; } } private int isHighBandwidth() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info.getType() == ConnectivityManager.TYPE_WIFI) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); return wm.getConnectionInfo().getLinkSpeed(); } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return tm.getNetworkType(); } return 0; } </code></pre> <p>An example usage would then be:</p> <pre><code>if (network) { if (bandwidth &gt; 16) { // Code for large items } else if (bandwidth &lt;= 16 &amp;&amp; bandwidth &gt; 8) { // Code for medium items } else { //Code for small items } } else { //Code for disconnected } </code></pre> <p>It's not the prettiest, but it allows enough flexibility that I can change the bandwidth cutoff for items depending on what they are and my requirements for them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload