1

I need a networkId of currently connected WiFi in order to disconnect device from that WiFi:

wifiManager.disconnect()
wifiManager.removeNetwork(i.networkId);
wifiManager.saveConfiguration()

I tried

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();

List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();

In both case, networkId is 0

On Galaxy S5 it works OK.

Any ideas, workarounds....?

3
  • I suppose the Galaxy S5 doesn't have android 6.0
    – abbath
    Nov 27, 2015 at 12:30
  • @abbath Yes, it is 5.0 Nov 27, 2015 at 13:51
  • Yeah, then it can be because of the 6.0 permission behaviour, as I mentioned in the answer.
    – abbath
    Nov 27, 2015 at 15:15

1 Answer 1

0

From 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 should be made. Giving a user an option to grant or deny.

For more information check this question.

2
  • Hm.. I am not targeting API 23. I understood that it will work in that case. If I am not right, that means all "older" apps will not work on 6.0 without new permission handling? Nov 27, 2015 at 15:22
  • Check this thread, it can be a bug.
    – abbath
    Nov 27, 2015 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.