My target is to scan wifi access points and show its SSID AND LEVEL(in dbm), but I have an problem in programming such that I can't to display it in listview or in toast meesage. I tried to write the below code and its looks like :
public class MainActivity extends Activity implements OnClickListener{
List<ScanResult> scanResults;
ArrayList<String> SSID_values;
ArrayList<Integer> level_values;
Button bt1;
WifiManager mWifiManager;
int size= 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button) findViewById(R.id.button1);
SSID_values = new ArrayList<String>();
level_values= new ArrayList<Integer>();
bt1.setOnClickListener(this);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
when button clicked, the following code is :
@Override
public void onClick(View v) {
mWifiManager.startScan();
// get list of the results in object format ( like an array )
scanResults = mWifiManager.getScanResults();
size = scanResults.size();
// loop that goes through list
// for (ScanResult scanResult : scanResults) {
for(int i = 0;i<=size;i++){
SSID_values.add(scanResults.get(size).SSID);
level_values.add(scanResults.get(size).level);
}
Toast.makeText(this, SSID_values + " " + level_values,
Toast.LENGTH_LONG).show();
}
Can any one help me?
Thank you in advance.