• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

android 27 - Connecting to wifi problem

mlgch1

Lurker
App used to connect ok with previous version (forget which one)
Under 27 the app it will not connect although the tablet itself is connecting.

Manifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.scorer.tennis_android">

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

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

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application

Code:
    private boolean checkWiFiConnected() {
        final WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);

        ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = null;
        if (cm != null) {
            networkInfo = cm.getActiveNetworkInfo();
        }

        WifiInfo wifiInfo = null;
        if (wifi != null) {
            wifiInfo = wifi.getConnectionInfo();
        }
        L.d("WifiSSID");
        L.d(WifiSSID);
        L.d("----");

        L.d("wifi");
        L.d(wifi);
        L.d("----");

        L.d("cm");
        L.d(cm);
        L.d("----");

        L.d("wifi.getWifiState()");
        L.d(wifi.getWifiState());
        L.d("----");

        L.d("wifiInfo");
        L.d(wifiInfo);
        L.d("----");

        L.d("networkInfo");
        L.d(networkInfo);
        L.d("----");

        L.d("wifiInfo.getSSID()");
        L.d(wifiInfo.getSSID());
        L.d("----");

LogCat

2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: WifiSSID (from App)
2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: scorer_8

2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: wifi
2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: android.net.wifi.WifiManager@e7ec6b9

2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: cm
2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: android.net.ConnectivityManager@89d2afe

2022-11-19 09:54:13.259 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: wifi.getWifiState()
2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: 3

2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: wifiInfo
2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: SSID: , BSSID: 02:00:00:00:00:00, MAC: 02:00:00:00:00:00, Supplicant state: COMPLETED, RSSI: -48, Link speed: 11Mbps, Frequency: 2462MHz, Net ID: 2, Metered hint: false, GigaAp: false, VenueName: null, score: 60

2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: networkInfo
2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: [type: WIFI[] - WIFI, state: CONNECTED/CONNECTED, reason: (unspecified), extra: "scorer_8", failover: false, available: true, roaming: false]

2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: wifiInfo.getSSID()
2022-11-19 09:54:13.260 14771-14771/com.scorer.tennis_android D/>==< Scorer >==<: <unknown ssid>

It appears that networkinfo is seeing the SSID (scorer_8) but getSSID gets "unknown SSID"

Why???? Much examination of Professor Google hasn't helped.
 
Is this been a problem for a long period of time or did it just start occurring?
Is this just happening when you're at home or does it happen when trying to connect to WiFi networks elsewhere?

If just at home, that indicates the problem is more likely to be with your router. Try just restarting your router, that often clears up any one-off glitches that occasionally occur. And just to be on the safe side reboot your tablet too if you don't do so periodically.
If this happens with other WiFi networks however, that does indicate a problem with your tablet. Try going into your tablet's Settings menu and deleting the WiFi network's entry. Then restart your tablet and re-enter that WiFi network again to see if that fixes the problem.
Those are basic things to always try first.
 
I am developing an app to run on a Samsung Tab A tablet which communicates to a Display showing scores. It does not involve any other wifi networks. It worked fine using the previous android version but no longer does with Android 27.
 
Problem fixed!!!

Although I had provided the suggested permissions in the Manifest file I needed to add the following code to get them granted.

Code:
if (wifi != null) {

    //If requested permission isn't Granted yet
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        //Request permission from user
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION);
    } else {                            //Permission already granted

        wifiInfo = wifi.getConnectionInfo();
    }
}
 
Back
Top Bottom