0

I have just started developing on android and need to be able to scan all the wifi signals in the area. This is needed to detect if you are in the area of a specific wifi signal and send a notification if this is the case. This needs to be done WITHOUT connecting to that wifi signal.

I have seen apps that detect all the wifi signals around, but have not been able to figure out how to do this. I need it to give me all the wifi points it would give you in the wifi settings on your phone.

I hope anyone can help me

  • 1
    possible duplicate of [Android WIFI How To Detect When Specific WIFI Connection is Available](http://stackoverflow.com/questions/9353005/android-wifi-how-to-detect-when-specific-wifi-connection-is-available) – Douglas Nassif Roma Junior Mar 12 '15 at 13:14

1 Answers1

0

Though this question might have duplicates, but I would like to answer as this question appears on my Google search in top 5.

To scan WiFi signals, you need to use the broadcast receiver ...

here is the example

 @Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_es_wi_fi_settings);
    this.manager = (WifiManager)(this.getSystemService(Context.WIFI_SERVICE));
    if(!manager.isWifiEnabled()){
        manager.setWifiEnabled(true);
     }
    receiver = new WifiReceiver();
    registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    manager.startScan();
}

Broadcast receiver for Wifi scan

class WifiReceiver extends BroadcastReceiver
{
    public void onReceive(Context c, Intent intent)
    {

            esWiFiSettings.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    List<ScanResult> results = manager.getScanResults();
                    if (results.size() <= 0)
                        return;
                    for (ScanResult result : results) {
                      Log.d(TAG, result.SSID);
                    }

                }
            });

    }

}

I hope above code is enough to get the idea,

JNI_OnLoad
  • 5,472
  • 4
  • 35
  • 60