public boolean isOnline() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean connected = (conMgr.getActiveNetworkInfo() != null &&
conMgr.getActiveNetworkInfo().isAvailable() &&
conMgr.getActiveNetworkInfo().isConnected())
return connected;
}
Also, you need to add permission to the app so that it can access network status.
Note: In emulator, you can press F8 to toggle the internet access.
No comments:
Post a Comment