Tag Archives: CONNECTED

Check if Connected to Internet & if isConnected to Wifi in Android.

By | November 6, 2014

This sample code checks whether the android device is connected to Internet and if it is connected to internet, it is connected to Wifi or Not? [java] package com.coderzheaven.demo1; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; public class MainActivity extends Activity { NetworkInfo activeNetwork; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (connectedToInternet()) System.out.println("Connected… Read More »

How to make sure the network is available in android?

By | October 5, 2010

Get all the available network connections [java] public boolean isNetworkAvailable() { Context context = getApplicationContext(); ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { Toast.makeText(this, "No conectivity", Toast.LENGTH_LONG).show(); } else { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { Toast.makeText(this, ""+info[i].getTypeName(),… Read More »