how to put network validation on Google Map,its working good when internet is up or WiFi is On.But not working when Internet is down
Asked
Active
Viewed 1,333 times
2
-
http://www.androidhive.info/2012/07/android-detect-internet-connection-status/ – Naveen Tamrakar Oct 22 '14 at 12:54
-
http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts – Naveen Tamrakar Oct 22 '14 at 12:54
-
first u check the net connection if connection here than open activity outher wise open dialog u have not net connection also have code to check net connection – Naveen Tamrakar Oct 22 '14 at 12:55
-
i am already checking internet connectivity and also WiFi status in my another project but don't know how to do in google maps – Ghufran Mehmood Oct 22 '14 at 12:57
-
check if net is no abliable than open some Toast net is not here – Naveen Tamrakar Oct 22 '14 at 12:59
-
yes i am showing but its working fine when wifi is off but not working when wifi is on but internet access is down – Ghufran Mehmood Oct 22 '14 at 13:01
-
your net connectiin is not working proper also check net connectiion in bath way like mobile data and wifi connection – Naveen Tamrakar Oct 22 '14 at 13:03
-
Do u have any example code ??? – Ghufran Mehmood Oct 22 '14 at 13:05
1 Answers
1
Please, try this. I hope it help you.
public static int TYPE_WIFI = 1;
public static int TYPE_MOBILE = 2;
public static int TYPE_NOT_CONNECTED = 0;
public static int getConnectivityStatus(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork) {
if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
return TYPE_WIFI;
if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
return TYPE_MOBILE;
}
return TYPE_NOT_CONNECTED;
}
public static String getConnectivityStatusString(Context context) {
int conn = NetworkUtil.getConnectivityStatus(context);
String status = null;
if (conn == NetworkUtil.TYPE_WIFI) {
status = "Wifi enabled";
} else if (conn == NetworkUtil.TYPE_MOBILE) {
status = "Mobile data enabled";
} else if (conn == NetworkUtil.TYPE_NOT_CONNECTED) {
status = "Not connected to Internet";
}
return status;
}

nurealam11
- 537
- 4
- 16