I just tested your code and it works for me. It shows the current connected SSID.
Edit: Your code shows the the current connected SSID (if connected), and it now looks like you want to get the list of all SSIDs currently in range.
Make sure you have your AndroidManifest.xml set up correctly:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Edit 2: Now that it is clear that you would like to get Scan Results and process them, I just worked out this simple example:
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import java.util.List;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView) this.findViewById(R.id.ScanResults);
WifiManager wifiManager = (WifiManager) this.getSystemService(this.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
final List<ScanResult> results = wifiManager.getScanResults();
if (results != null) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < results.size(); i++) {
String ssid = results.get(i).SSID;
if (ssid.startsWith("sv-")) {
buf.append(ssid + "\n");
}
}
text.setText(buf.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
In activity_main.xml:
<TextView
android:id="@+id/ScanResults"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />