Aplicativo que liste redes wifi disponiveis

Estou tentando criar um app que lista as redes wifi próximas. Eis meu código `import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import java.util.List;
import wifipassword.pedrodev.com.br.wifipassword.R;

public class ActivityPrincipal extends AppCompatActivity {

public TextView textView;
public  WifiManager wifi;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    textView = (TextView) findViewById(R.id.texto);

    Context c = this;
    wifi = (WifiManager)c.getSystemService(c.WIFI_SERVICE);

    Scan scan = new Scan();

    boolean i = wifi.startScan();
    registerReceiver(scan, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    Log.i("onCreate", "Chamei startScan()");
    Log.i("onCreate", "" + i);
}

// Classe Interna Responsavel por Listar as redes Wifi Disponiveis
public class Scan extends BroadcastReceiver {

    List<ScanResult> wifis;

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.i("onReceive", "fui invocado");


        wifis = wifi.getScanResults();

        StringBuilder stringBuilder = new StringBuilder();

        if (wifis.size() > 0) {
            Log.i("onReceive", "wifis cheio");
        } else {
            Log.i("onReceive", "wifis vazio");
        }

        for (ScanResult sc : wifis) {
            stringBuilder.append(sc.SSID);
            stringBuilder.append("-");
            stringBuilder.append(sc.BSSID);

            stringBuilder.append(sc.toString());

            Log.i("onReceive", "Contatenei " + sc);
        }

        Log.i("TESTE TESTE TESTE TESTE", "TESTE TESTE TESTE TESTE");

    }
}

}
`
Porém o scanResult sempre está vazio msm tendo wifi proximos, alguém já fez algo parecido e sabe onde estou errando?

1 curtida