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.
Asked
Active
Viewed 890 times
1 Answers
1
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!!

Community
- 1
- 1

thereleventfridge
- 56
- 3
-
it's work fine adding activity instance like this...ConnectivityManager cm = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE);! thanks.. – user749873 Mar 13 '12 at 17:48