I am currently developing a sort of wifi sniffer. To achieve that I use a tcpdump binary compiled for arm. But it\'s assume that I know the name of the Wifi Interface.
All the answers related to this question are not straight-forward. But you can achieve this by reflection. The code mentioned below will work even when there is no wifi connection.
String interfaceName=null;
try {
Method m = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
interFace = (String) m.invoke(null, "wifi.interface");
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("Wifi Interface Name: " + interfaceName);
It is working on all the api levels (even when your targetsdk will be 30 inspite of some limitations added in reflection).