About Me

Age:25 --- B.E.(Computer Science), Android/Java Developer, CCNA, CCNA SECURITY (IINS), CCNP (R&S), 4011 Recognized(NSA & CNSS)U.S.A. , MCSA, MCTS, REDHAT CERTIFIED NETWORK SECURITY ADMINISTRATOR(RH253), AFCEH.

Saturday, August 24, 2013

Android code to scan the available SSIDs

       

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
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.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
 WifiManager wifi;
 Button buttonScan;
 int size = 0;
 String ITEM_KEY = "key";
 List results;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  buttonScan = (Button) findViewById(R.id.button_Scan);

  if (wifi.isWifiEnabled() == false) {
   Toast.makeText(getApplicationContext(),
   "wifi is disabled..making it enabled", Toast.LENGTH_LONG)
     .show();
   wifi.setWifiEnabled(true);
  }

  buttonScan.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {

    wifi.startScan();
    for (ScanResult sx : wifi.getScanResults()) {
     System.out.println("Point - " + sx);
    }

   }
  });
 }
}

       
 

No comments:

Post a Comment