Tag Archives: Wifi

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 check different Network status in Android?

By | May 5, 2012

This code snippet checks which of your networks are available in android. [java] package com.coderzheaven.pack; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.os.Bundle; import android.widget.Toast; public class CheckConnectionsDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); checkAvailableConnection(); } void checkAvailableConnection() { ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile =… Read More »

How will you programatically enable or disable WIFI in android?

By | September 30, 2011

Hello all.. This is a simple code snippet to enable WI-FI in android programatically in android. [java] public boolean enableWIFI() { WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if(wifiManager.isWifiEnabled()){ if(wifiManager.setWifiEnabled(false)) return true; }else{ if(wifiManager.setWifiEnabled(true)) return true; } return false; } [/java] Note : Make sure to add the permissions in the manifest file. These are the permissions. [xml] <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"… Read More »