Using Robotiumin how to check or make a test case to check the network connection availability in android?

StackOverflow https://stackoverflow.com//questions/9688451

Question

I am new in android testing I am using Robotium for testing purpose and I have a scenario where I need to check is the network (WiFi, 3G, 2G)connection is available or not, so how can i write a test case for this. Please help to solve this.. Thanks.

Was it helpful?

Solution

Source: How to check internet access on Android? InetAddress never times out

public boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

You'll need these in your manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I personally had to run a specific check to see if the user could access my server (Possibility of firewall blocking, or the user having only a local connection)

Good Luck!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top