error -2 internet connection availibality code? plz help me thanks i am using this for android application i need to put a code that checks the internet availibity and then it should give me an error message that ur not connected if i am not connected thanks
Asked
Active
Viewed 149 times
-3
-
deplicated Have a Look http://stackoverflow.com/questions/9570237/android-check-internet-connection – Naveen Tamrakar Aug 30 '14 at 07:53
-
yes sir, i didnt see that sorry – Bashir Ahmed Iqbali Aug 30 '14 at 07:57
1 Answers
0
This function will help you to check network is connected or not.
public boolean isNetworkConnected(Context cntx) {
ConnectivityManager cm = (ConnectivityManager) ((Activity) cntx)
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
Toast.makeText(cntx, "No Network Connection ! ",
Toast.LENGTH_LONG)
.show();
return false;
} else {
return true;
}
}

XEENA
- 569
- 2
- 6
-
r u sure bro, wont this code interfere with any of other codings that i did on my project...? – Bashir Ahmed Iqbali Aug 30 '14 at 08:06
-