I would like to make a page that would automatically check the user's current network status when the application is started-up, and redirect the user to different page. When there is no network was connected, it will redirect the user to a specific page (eg. no_network_connected.xml). Otherwise, it will bring the user to the (main.xml) page.
Asked
Active
Viewed 595 times
1 Answers
1
this method checks whether mobile is connected to internet and returns true if connected:
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
// There are no active networks.
return false;
} else
return true;
}
in manifest,
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-
so, how can I use this method to let the activity automatic redirect to different pages according to the network state? – 21.kaw Nov 05 '13 at 14:37
-
1This is another question, maybe you need to start with java basis than going through android application directly. – RamonBoza Nov 05 '13 at 14:39