Android WIFI How To Detect When Specific WIFI Connection is Available

You can use BroadcastReceiver to find out that wifi network has changed: BroadcastReceiver broadcastReceiver = new WifiBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); context.registerReceiver(broadcastReceiver, intentFilter); The BroadcastReceiver may look like this. And to check for specific MAC address see the checkConnectedToDesiredWifi() method bellow. public class WifiBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent … Read more

How do I use CaptiveNetwork to get the current WiFi Hotspot Name

You need to find out which networks are available, and then pass them into CNCopyCurrentNetworkInfo. For example: CFArrayRef myArray = CNCopySupportedInterfaces(); CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); …and you can then use the kCNNetworkInfoKeySSID on the dictionary you’ve got back (myDict) to find out the SSID. Don’t forget to release/manage memory appropriately.

Java getting my IP address

String ip; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); // filters out 127.0.0.1 and inactive interfaces if (iface.isLoopback() || !iface.isUp()) continue; Enumeration<InetAddress> addresses = iface.getInetAddresses(); while(addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); ip = addr.getHostAddress(); System.out.println(iface.getDisplayName() + ” ” + ip); } } } catch (SocketException e) { throw new … Read more

Set Android IP,DNS,GATEWAY setting programmatically

You can change system settings programatically. First you need to request the ‘WRITE_SETTINGS’ permission in your ‘AndroidManifest.xml’: <uses-permission android:name=”android.permission.WRITE_SETTINGS”/> Then you need to actually change the setting using the following code: android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, “0”); android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1, “192.168.0.2”); android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS2, “192.168.0.3”); android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY, “192.168.0.1”); android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK, “255.255.255.0”); android.provider.Settings.System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP, “1”); The current settings can be accessed … Read more

Check for Active internet connection Android

It does works for me: To verify network availability: private Boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting(); } To verify internet access: public Boolean isOnline() { try { Process p1 = java.lang.Runtime.getRuntime().exec(“ping -c 1 www.google.com”); int returnVal = p1.waitFor(); boolean reachable = (returnVal==0); return … Read more

Getting MAC address in Android 6.0

Please refer to Android 6.0 Changes. To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00. To access the hardware identifiers of nearby … Read more