0

我的目标是扫描 wifi 接入点并显示其 SSID 和级别(在 dbm 中),但我在编程时遇到问题,无法在列表视图或 toast 消息中显示它。我试图编写下面的代码,它看起来像:

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);
    }

单击按钮时,以下代码为:

@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();

    }

谁能帮我?

先感谢您。

4

0 回答 0