0

I am not able to get the Wi-FI information such as SSID name through code in Google Pixel 3.

It works with other devices like Samsung S10, Oneplus 6 etc.

WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  if (wifiInfo != null) {
      NetworkInfo.DetailedState state =WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
     if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
       return wifiInfo.getSSID();
     }
}
Rahul
  • 481
  • 4
  • 9
  • @BlackBlind I tested this in Nokia 6,Samsung S10 with OS version Pie. I can able to get the SSID name. – Rahul Mar 29 '19 at 11:10
  • What is your phone Os? Is it Q? – BlackBlind Mar 29 '19 at 11:32
  • This doesn't seem to be a duplicate of the referenced topic. This topic specifically mentions Google Pixel 3 as the only phone that doesn't work and lists Samsung S10, etc., as working. The other topic doesn't mention Google Pixel 3 at all. Instead it mentions a Nokia phone as the problem. – deLock Jul 05 '19 at 11:37

3 Answers3

0

I think this problem related to Android latest versions.

You need to CHANGE_WIFI_STATE for Android Pie.

You can try my solution from this Link

Hope it works for you !

  • Not worked. I had CHANGE_WIFI_STATE in Manifest and connManager.getNetworkInfo() is also deprecated. – Rahul Mar 29 '19 at 10:22
0

I use it with BroadcastReceiver. My using code try this;

  private boolean checkInternet(Context context) {
  ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo = cm.getActiveNetworkInfo();
     return networkInfo != null && networkInfo.isConnected();
    }
Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41
0

You should have to add these permission in manifest file first.

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

Now add this code in your activity.

ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (networkInfo.isConnected()) {
            WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            wifiInfo.getSSID();
            String name = networkInfo.getExtraInfo();
            String ssid = "\"" + wifiInfo.getSSID() + "\"";
}

It will help you get wifi name in pie devices.

BlackBlind
  • 772
  • 9
  • 26