I want to check the Internet connection available or not in device so how can i got this..please give me code for this..
thank a lot In advance
I want to check the Internet connection available or not in device so how can i got this..please give me code for this..
thank a lot In advance
hey buddy...apply this code..it might be helpful to u.thanks in advance....
boolean connected;
private boolean checkInternetConnection()
{
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
// ARE WE CONNECTED TO THE NET
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected())
{
return true;
}
else
{
return false;
}
}
ConnectivityManager connectionService =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (connectionService.getActiveNetworkInfo().isConnectedOrConnecting()) {
// Device is online
}
// Network is connected or not
public boolean isConnected()
{
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
Log.d("LOG","Network is Available");
return true;
}
}
return false;
}
Use the following function inorder to check the internet connction:
public boolean isOnline()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
boolean result = false;
if(ni != null )
{
if( ni.getState() == NetworkInfo.State.CONNECTED )
{
result = true;
}
}
return result;
}
check what isOnline() returns .If true then Internet is connected else Inernet is not connected . Hope this will help you..:)
Use this Answer It`s help.
public boolean isOnline() {
ConnectivityManager cm =(ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
if(temp==true){
genHelper.showToast("Net Connection");
}else{
genHelper.showToast(" Not Connected");
}