Paul Hunnisett
Paul Hunnisett

Reputation: 908

Determine data signal strength

I know that it's possible to determine the data connection type (WIFI/or cellular) through Android, but is it possible to determine the cellular connection type and strength?

I have an app that downloads some images and I have found that on GPRS or on 3G with weak signal that this download process slows up the app unacceptably. What I want to do is say that if you have either WIFI or a strong and fast data connection then download; otherwise display a default placeholder image.

Any clues on how to do this?

Upvotes: 4

Views: 3404

Answers (2)

Najd
Najd

Reputation: 41

  • Determining the radio technology (network type) is simple:

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

int nt = tm.getNetworkType();

    switch (nt) {
            case 1: return GPRS;
            case 2: return EDGE;
            case 3: return UMTS;
            case 8: return HSDPA;
            case 9: return HSUPA;
            case 10:return HSPA;
            default:return UNKNOWN;
            }
  • If you want to estimate the download time you must mesure the bandwidth in Kbps by opening socket connection for example .. But that is too complicated! I suggest you to try to download the image in AsyncTask anyway and set a timer limit to say 5 seconds. If the download is not achived then stop the asynctask and display a default placeholder image.

Upvotes: 3

Octavian Helm
Octavian Helm

Reputation: 39604

How about not blocking the UI thread and running long running tasks in a background thread where they belong to?

Look up the reference on AsyncTask and the article on threading called Painless Threading.

Update: Alright then lookup the reference page on ConnectivityManager which does just what you want.

Update2: Just realized that you wanted to know about the signal strength. In that case you need to lookup the SignalStrength class.

Upvotes: 2

Related Questions