ChanChow
ChanChow

Reputation: 1366

Implementing service in Android for recognizing wifi networks

I am trying to create a new Android application in which I have to recognize any new and existing wifi networks in its range.

So I need a service which runs at backend all the time. I checked at Service and IntentService classes through which I thought could implement this. But I am not sure which one to use, either service or Intentservice?

Upvotes: 0

Views: 42

Answers (1)

Micik
Micik

Reputation: 129

In order to check network connection availability you can use the following code:

public boolean isNetworkAvailable() {
    ConnectivityManager myconnectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (myconnectivity == null) {
        return false;
    } else {
        NetworkInfo[] myinfo = myconnectivity.getAllNetworkInfo();
        if (myinfo != null) {
            for (int i = 0; i < myinfo.length; i++) {
                if (myinfo[i].isConnected()) {
                    return true;
                }
            }
        }
    }
    return false;
}

You can examine myinfo[i] instances to check if this network type is wifi or not. Please refer to the documentation on this: http://developer.android.com/reference/android/net/NetworkInfo.html

Upvotes: 1

Related Questions