1

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.

21.kaw
  • 583
  • 2
  • 7
  • 18

1 Answers1

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" />

from Android check internet connection

Community
  • 1
  • 1
RamonBoza
  • 8,898
  • 6
  • 36
  • 48
  • 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
  • 1
    This is another question, maybe you need to start with java basis than going through android application directly. – RamonBoza Nov 05 '13 at 14:39