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....?

Bozic Nebojsa
  • 3,606
  • 1
  • 19
  • 17

1 Answers1

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.

Community
  • 1
  • 1
abbath
  • 2,444
  • 4
  • 28
  • 40
  • 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? – Bozic Nebojsa Nov 27 '15 at 15:22
  • [Check this thread](http://stackoverflow.com/questions/22592353/wifimanager-getconfigurednetworks-always-returns-empty-list), it can be a bug. – abbath Nov 27 '15 at 15:29