Forgot network not working in Android Marshmallow? - android

I am using below code to remove or forgot configure Wi-Fi network:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.removeNetwork(networkID);
but its not working in os 6.0, please suggest?

You should use like this:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int networkId = wifiManager.getConnectionInfo().getNetworkId();
wifiManager.removeNetwork(networkId);
wifiManager.saveConfiguration();
Hope it will helps you !!

Related

How can i get wifi signal strength in Android Programmatically?

Any one help me out to fetch wifi Signal strength ?
You can get the signal in levels by using:
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int levels = 5;
WifiInfo wifiInfo = wifi.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
Refer to this answer for further help.

Android SupplicantState returns COMPLETED after disconnecting from network

The problem:
When I connect to wifi, and then disconnect, the following code gives me SupplicantState.COMPLETED
SupplicantState supState;
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();

Trigger update of ScanResult android wifi

Is it possible to trigger an update of the scan result for wifi on an Android phone? So when you use the example code below you dont get cashed values.
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> results = wifiManager.getScanResults();
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
List<ScanResult> results = wifiManager.getScanResults();

Can't set "WifiConfiguration" when enabling wifi-hotspot using "setWifiApEnabled"

I'm trying to set my Android device to be an Access-Point using the code I've seen here before:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "MyAccessPoint";
Method method = wifi.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifi, netConfig, true);
now, I managed to turning it on but without the SSID which I set in WifiConfiguration.
This is driving me crazy.
Anyone?
Before Invoking the Method "setWifiApEnabled" you need to call "getWifiApConfiguration" to get the default WifiConfiguration
Then change the SSID and Password and then invoke "setWifiApConfiguration" with the modified WifiConfiguration and after that call "setWifiApEnabled"
Here is the Code.
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
getWifiConfig = wifi.getClass().getMethod("getWifiApConfiguration",null);
WifiConfiguration myConfig = (WifiConfiguration) getWifiConfig.invoke(wifi,null);
myConfig.SSID = "Hello World";
setWifiConfig = wifi.getClass().getMethod("setWifiApConfiguration",WifiConfiguration.class);
setWifiConfig.invoke(wifi,new Object[]{myConfig,true});
enableWifi = wifi.getClass().getMethod("setWifiEnabled",WifiConfiguration.class,boolean.class);
enableWifi.invoke(wifi,null,true);
See how I got this working at Android 2.3 wifi hotspot API.

how to get MacID of mobiledevice in android?

how to get MacID of mobiledevice in android?
try this
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = manager.getConnectionInfo();
String MACAddress = wifiInfo.getMacAddress();

Categories

Resources