android-wifi
Connect to Wifi in Android Q programmatically
So far what is working for me on the majority of devices I have tested with, with a fallback option to at least stop the dreaded ‘looping request’ and to allow a successful manual connection The below code is written in Kotlin, please google how to covert to Java if needed. Create a NetworkCallback which … Read more
How to get each device’s IP address in Wi-Fi Direct scenario?
I encountered the same problem. Since both devices know the group owner’s ip, it is already possible to send a message to the group owner. The first message you send can contain the ip address of the other device; from then on, bidirectional communication is possible. Here’s a possibility for retrieving your ip in java: … Read more
Android 2.3 wifi hotspot API
There is no official API, but you can use reflection to handle it. I know some say, it’s not recommended, however imho I say, screw it if Google doesn’t want to provide an API for whatever reason. Below is the code of an activity I used in my application, where the user can enable/disable the … Read more
How to turn off Wifi via ADB?
Using “svc” through ADB (rooted required): Enable: adb shell su -c ‘svc wifi enable’ Disable: adb shell su -c ‘svc wifi disable’ Using Key Events through ADB: adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 20 & adb shell input keyevent 23 The first line launch “wifi.WifiSettings” activity which open the … Read more
How to get name of wifi-network out of android using android API?
android.net.wifi.WifiInfo.getSSID? WifiManager wifiMgr = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); String name = wifiInfo.getSSID();
android: Determine security type of wifi networks in range (without connecting to them)
I think you can find it in the source code of Settings.apk. First you should call wifiManager.getConfiguredNetworks() or wifiManager.getScanResults(), then use the two methods below: (find them in AccessPoint class “com.android.settings.wifi”): static int getSecurity(WifiConfiguration config) { if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) { return SECURITY_PSK; } if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) { return SECURITY_EAP; } return (config.wepKeys[0] != null) ? … Read more
How to get available wifi networks and display them in a list in android
You need to create a BroadcastReceiver to listen for Wifi scan results: private final BroadcastReceiver mWifiScanReceiver = new BroadcastReceiver() { @Override public void onReceive(Context c, Intent intent) { if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { List<ScanResult> mScanResults = mWifiManager.getScanResults(); // add your logic here } } } In onCreate() you would assign mWifiManager and initiate a scan: mWifiManager = … Read more
Android Studio – Android Emulator Wifi Connected with No Internet
Stated below are the solutions for Windows and Mac, but similar solutions will work on any OS: On Windows Open Network and Sharing Center and click on current Connection Click on Properties Double Click on Internet Protocol Version 4 (TCP/IPv4) Set the Preferred and Alternate DNS servers as (Screenshot below) : 8.8.8.8 8.8.4.4 On Mac … Read more
How to turn on/off wifi hotspot programmatically in Android 8.0 (Oreo)
I thought the LocalOnlyHotspot route was the way to, but as @edsappfactory.com said in the comments – it only gives closed network, no internet access. In Oreo hot-spotting/tethering moved to ConnectionManager, and its annotated @SystemApi, so (nominally) inaccessible. As part of something else I was doing, I made an app and put it on github … Read more