How to update wifi RSSI values without a click button

岁酱吖の 提交于 2019-12-25 04:19:23

问题


Basically, I can list the values of RSSI in a ListView through a SimpleAdapter.

public class ActivityListarRedes extends MainActivity {


@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listar_redes);


    List<Map<String, String>> l = listaRedes();


    String[] from = { "ExampleId", "ExampleName" };
    int[] to = { android.R.id.text1, android.R.id.text2 };

    SimpleAdapter ad = new SimpleAdapter(this, l, simple_list_item_2, from, to);
    ListView lv = (ListView) findViewById(R.id.list);
    lv.setAdapter(ad);




}

public List<Map<String, String>> listaRedes() {

        networks = new ArrayList<ScanResult>();
        wifi.startScan();
        networks = wifi.getScanResults();

        List<Map<String, String>> l = new ArrayList<Map<String, String>>();

        for (ScanResult net : networks) {
            Map<String, String> m = new HashMap<String, String>();
            m.put("ExampleId", "Rede: " + net.SSID);
            m.put("ExampleName", "RSSI: " + net.level + "dBm");
            l.add(m);
        }
        return l;
    }

Now, I would like to know if it's possible to update the values of RSSI given by method "listaRedes" which is a List. Maybe I could call the method "listaRedes" during some time until I pause it or click in some button to pause.

Will be that possible ?

Thanks


回答1:


Update: You can take a look at my demo for RF measurements using Android device, here:

https://github.com/panosvas/Measurements

where you can find an implementation of WiFi measurements one after another. I have also created a Server for storing these measurements as well as a remote trigger app using UDP packets where you can find here:

https://github.com/panosvas/IndoorPositioningServer

It is possible to update your list. You can take a look in my answer here:

Wifi Scanner which scans 20 times

In order to adapt it to your needs you don't want the counter and instead of it, in the onRecieve each time you will trigger again the task that calls the startScan() method.

Don't forget to unregister the listener on the onDestroy.

Hope this helps.



来源:https://stackoverflow.com/questions/22201610/how-to-update-wifi-rssi-values-without-a-click-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!