title: Create an app which shows wifi available connections
body: <p>I am trying to create an app which will show the Wifi connections</p>
  
  <pre><code>package com.example.amit.ak503;
  import java.util.List;
  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.Handler;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Switch;
  import android.widget.Toast;
  
  import java.lang.reflect.Array;
  
  import java.util.ArrayList;
  
  import java.util.List;
  
  
  public class MainActivity extends AppCompatActivity {
  static int LENGTH_SHORT=600;
  
  Switch s1;
  WifiManager obj1;
  WifiReceiver obj2;//obj of parent broadcastReceiver class
  StringBuilder sb=new StringBuilder();
  private final Handler handler=new Handler();
  @Override
  public  void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      obj1=(WifiManager)getSystemService(Context.WIFI_SERVICE);
      s1=(Switch)findViewById(R.id.switch1);
      s1.setChecked(true);
      obj2=new WifiReceiver();
      registerReceiver(obj2,new 
  IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
     s1.setOnClickListener(new
                                   View.OnClickListener() {
                                       @Override
                                       public void onClick(View v) {
  
                                           if(s1.isChecked())
                                           {
                                               obj1.setWifiEnabled(true);
  
  Toast.makeText(MainActivity.this,"Wifi enabled",Toast.LENGTH_SHORT).show();
                                           }
                                           else
                                           {
                                               obj1.setWifiEnabled(false);
  
  Toast.makeText(MainActivity.this,"Wifi Disabled",Toast.LENGTH_SHORT).show();
                                           }
                                           doInback();
                                       }
                                   });
  
  }
  public void doInback()
  {
      handler.postDelayed(new Runnable() {
          @Override
          public void run() {
              obj1=(WifiManager)getSystemService(Context.WIFI_SERVICE);
              obj2=new WifiReceiver();
              registerReceiver(obj2,new 
  IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
              obj1.startScan();
              doInback();
          }
      },1000);
  }
  public boolean onCreateOptionsMenu(Menu menu)
  {
      menu.add(0,0,0,"Refresh");
      return super.onCreateOptionsMenu(menu);
  }
  public boolean onOptionsItemSelected(MenuItem item)
  {//replaced onMenuItemSelected(featuredid,MenuItem item) with 
  onOptionsItemSelected(MenuItem item)
      obj1.startScan();
  
  Toast.makeText(MainActivity.this,"Refreshing",Toast.LENGTH_SHORT).show();
      return super.onOptionsItemSelected(item);
  }
  @Override
  protected void onPause()
  {
      unregisterReceiver(obj2);
      super.onPause();
      Toast.makeText(MainActivity.this,"Unregistering 
  Receiver",Toast.LENGTH_SHORT).show();
  }
  @Override
  protected void onResume()
  {
      registerReceiver(obj2,new 
  IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
      super.onResume();
      Toast.makeText(MainActivity.this,"Registering 
  Receiver",Toast.LENGTH_SHORT).show();
  }
  class WifiReceiver extends BroadcastReceiver
  {
      public void onReceive(Context c,Intent intent)
      {
          //Toast.makeText(MainActivity.this,"onReceive 
  Started",Toast.LENGTH_SHORT).show();
          ArrayList&lt;String&gt; connections=new ArrayList&lt;String&gt;();
          ArrayList&lt;Float&gt; Signal_strength=new ArrayList&lt;Float&gt;();
  
  sb=new StringBuilder();
          List&lt;ScanResult&gt; wifiList;
          wifiList=obj1.getScanResults();
          for(int i=0;i&lt;wifiList.size();i++)
          {
              connections.add(wifiList.get(i).SSID);
          }
  
  
      }
  
      }
  </code></pre>
  
  <p>the Xml code is as-:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.amit.ak503.MainActivity"&gt;
  
  &lt;Switch
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="New Switch"
      android:id="@+id/switch1"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  
  }
  </code></pre>
  
  <p>the problem with this is that it does not the available wificonnections. Button is working properly.</p>