In manifest file have to add a new permission
android.permission.ACCESS_NETWORK_STATE
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork.isConnectedOrConnecting();
if (isConnected != true){
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Ineternet Connection");
alertDialog.setMessage("Not available");
alertDialog.show();
}
else
{
// rest code
}
android.permission.ACCESS_NETWORK_STATE
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork.isConnectedOrConnecting();
if (isConnected != true){
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Ineternet Connection");
alertDialog.setMessage("Not available");
alertDialog.show();
}
else
{
// rest code
}
No comments:
Post a Comment