George
George

Reputation: 19

Get the WIFI ID in android

I have checked similar questions and I got this far:

 WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
 WifiInfo wifiInfo = wifiManager.getConnectionInfo();
 String wifiInfo2 = wifiInfo.toString();

This returns a long line: SSID: WiredSSID, BSSID: etc....

What I want to print is the WIFI the phone is connected too. In this case "SKYsomething". Is there a way to get the wifi that the phone is connected to? ex:IF I connect my phone to "SKYtest", is there a way to get that name through code? I tried to keep it simple and direct but i could be missing something. Thanks for all the help.

Upvotes: 0

Views: 1968

Answers (1)

JpCrow
JpCrow

Reputation: 5077

try with:

     WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
     WifiInfo wifiInfo = wifiManager.getConnectionInfo();
     String wifiInfo2 = wifiInfo.getSSID();

And if you preffer this is better solution:

    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    String ssid = wifiManager.getConnectionInfo().getSSID();

Dont forget to add in your manifest the following permission

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">

Upvotes: 1

Related Questions