Android Q, programmatically connect to different WiFi AP for internet

Try calling bindProcessToNetwork() in onAvailable() callback to regain network connectivity, it works fine for me. Connect to network: WifiNetworkSpecifier.Builder builder = new WifiNetworkSpecifier.Builder(); builder.setSsid(“wifi-ap-ssid”); builder.setWpa2Passphrase(“wifi-ap-password”); WifiNetworkSpecifier wifiNetworkSpecifier = builder.build(); NetworkRequest.Builder networkRequestBuilder1 = new NetworkRequest.Builder(); networkRequestBuilder1.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); networkRequestBuilder1.setNetworkSpecifier(wifiNetworkSpecifier); NetworkRequest nr = networkRequestBuilder1.build(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { @Override public void onAvailable(Network … Read more

android how to check wifi is connected but no internet connection

NetworInfo.isAvailable and NetworkInfo.isConnected only indicate whether network connectivity is possible or existed, they can’t indicate whether the connected situation has access to the public internet, long story short, they can’t tell us the device is online indeed. To check whether a device is online, try the following methods: First: @TargetApi(Build.VERSION_CODES.M) public static boolean isNetworkOnline1(Context context) … Read more

how to install CA certificate programmatically on Android without user interaction

You can only install certificates silently if you have system privileges. Showing up a confirmation dialog is intentional, since trusting certificates can have serious consequences — Android could happily open phishing sites without a warning, etc. That said, the dialog in ICS/JB is pretty bad — it doesn’t tell you what certificate you are installing … Read more

How users/developers can set the Android’s proxy configuration for versions 2.x?

I don’t think there was any platform-level support for Wi-Fi proxies before Gingerbread or prerhaps Honeycomb. Edit: An Android engineer who works on this part of the platform confirms that the system didn’t have proxies for different network types (e.g., Wi-Fi) until Honeycomb. So there is no “official” way to get the Wi-Fi proxy for … Read more

Send request over WiFi (without connection) even if Mobile data is ON (with connection) on Android M

Stanislav‘s answer is correct but incomplete because only works in Lollipop. I’ve wrote a complete solution for Lollipop and Marshmallow onwards for you to route all network requests through WiFi when connected to a specific network of your choice. Kotlin In your Activity, @RequiresApi(Build.VERSION_CODES.LOLLIPOP) class RoutingActivity : Activity() { private var mConnectivityManager: ConnectivityManager? = null … Read more

Getting WiFi signal strength in Android

its an old post but this might help someone… WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int numberOfLevels = 5; WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels); Documentation: public static int calculateSignalLevel (int rssi, int numLevels)

CONNECTIVITY_ACTION intent received twice when Wifi connected

NOTE: For a recent, up-to-date answer, see this one below! After a lot of googling and debugging, I believe this is the correct way to determine if Wifi has connected or disconnected. The onReceive() method in the BroadcastReceiver: public void onReceive(final Context context, final Intent intent) { if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if(networkInfo.isConnected()) { … Read more