2012-06-01 1 views

답변

2
WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE). 

String currentSSID = mng.getConnectionInfo().getSSID() 
+0

이 답변은 중복 질문에 설명되어 있습니다. 그것이 대답했던 것에 따라 그것은 나의 wifi 핫스팟 ssid를 얻을 수 없다! – Nolesh

+0

오류가 있습니까? 아니면 반환 된 문자열이 비어 있습니까? – VinceFR

+0

아니요. 내 WiFi 공유기의 SSID를 돌려줍니다. – Nolesh

3

조금 늦었지만 최근에 장치의 핫스팟의 SSID를 가져올 수있었습니다. 그것은 내 Galaxy Nexus에서 작동하지만 꽤 많이 테스트하지는 않았습니다.

public static WifiConfiguration getWifiApConfiguration(final Context ctx) { 
    final WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); 
    final Method m = getWifiManagerMethod("getWifiApConfiguration", wifiManager); 
    if(m != null) { 
     try { 
      return (WifiConfiguration) m.invoke(wifiManager); 
     } catch(Exception e) { 
     } 
    } 
    return null; 
} 

private static Method getWifiManagerMethod(final String methodName, final WifiManager wifiManager) { 
    final Method[] methods = wifiManager.getClass().getDeclaredMethods(); 
    for (Method method : methods) { 
     if (method.getName().equals(methodName)) { 
      return method; 
     } 
    } 
    return null; 
} 

핫스팟 이름을 가져 오려면 getWifiApConfiguration (getActivity()). SSID를 호출하기 만하면됩니다. Nullpointer 검사가 전에 권장됩니다;)