Wifi Connect-Disconnect Listener

Actually you’re checking for whether Wi-Fi is enabled, that doesn’t necessarily mean that it’s connected. It just means that Wi-Fi mode on the phone is enabled and able to connect to Wi-Fi networks. This is how I’m listening for actual Wi-Fi connections in my Broadcast Receiver: public class WifiReceiver extends BroadcastReceiver { @Override public void … Read more

SCAN_RESULTS_AVAILABLE_ACTION return empty list in Android 6.0

As of Android 6.0, permission behaviour has changed to runtime. To use a feature that requires a permission, one should check first if the permission is granted previously. Using checkSelfPermission(permissionString) method a result is returned, wither ther permission is PERMISSION_GRANTED or PERMISSION_DENIED. If permission isn’t granted or it is first time, a request for permission … Read more

Android turn On/Off WiFi HotSpot programmatically

Warning This method will not work beyond 5.0, it was a quite dated entry. Use the class below to change/check the Wifi hotspot setting: import android.content.*; import android.net.wifi.*; import java.lang.reflect.*; public class ApManager { //check whether wifi hotspot on or off public static boolean isApOn(Context context) { WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE); try { Method … Read more

How can I get Android Wifi Scan Results into a list?

Try this code public class WiFiDemo extends Activity implements OnClickListener { WifiManager wifi; ListView lv; TextView textStatus; Button buttonScan; int size = 0; List<ScanResult> results; String ITEM_KEY = “key”; ArrayList<HashMap<String, String>> arraylist = new ArrayList<HashMap<String, String>>(); SimpleAdapter adapter; /* Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); … Read more

How to programmatically create and read WEP/EAP WiFi configurations in Android?

Part 1: Creating a WEP WiFi configuration programmatically This is pretty much straightforward, WifiConfiguration exposes the interface to create the same. Here is the sample code: void saveWepConfig() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiConfiguration wc = new WifiConfiguration(); wc.SSID = “\”SSID_NAME\””; //IMP! This should be in Quotes!! wc.hiddenSSID = true; wc.status = WifiConfiguration.Status.DISABLED; wc.priority … Read more

How to detect when WIFI Connection has been established in Android?

You can register a BroadcastReceiver to be notified when a WiFi connection is established (or if the connection changed). Register the BroadcastReceiver: IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); registerReceiver(broadcastReceiver, intentFilter); And then in your BroadcastReceiver do something like this: @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { … Read more

How do I see if Wi-Fi is connected on Android?

You should be able to use the ConnectivityManager to get the state of the Wi-Fi adapter. From there you can check if it is connected or even available. ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi.isConnected()) { // Do whatever } NOTE: It should be noted (for us n00bies here) that you … Read more

Broadcast receiver for checking internet connection in android app

Answer to your first question: Your broadcast receiver is being called two times because You have added two <intent-filter> Change in network connection : <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” /> Change in WiFi state: <action android:name=”android.net.wifi.WIFI_STATE_CHANGED” /> Just use one: <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” />. It will respond to only one action instead of two. See here for more information. … Read more

How do I connect to a specific Wi-Fi network in Android programmatically?

You need to create WifiConfiguration instance like this: String networkSSID = “test”; String networkPass = “pass”; WifiConfiguration conf = new WifiConfiguration(); conf.SSID = “\”” + networkSSID + “\””; // Please note the quotes. String should contain ssid in quotes Then, for WEP network you need to do this: conf.wepKeys[0] = “\”” + networkPass + “\””; … Read more