简体   繁体   中英

how to scan wifi every minute android

I have use timertask to rescan wifi every 10 second , but it only works when I resume to the activity. how can it be automatically update wifi signal after I start the activty?

 protected void onResume() {

        tim.schedule(new TimerTask() {
            @Override
            public void run() {
                wifi.startScan();
                wifiLists = wifi.getScanResults();
            }
        },0,10000);

            for (int i = 0; i < wifiLists.size(); i++) {
                if(wifiLists.get(i).SSID.equals( "eduroam"))
                {
                    mSSID.setText("SSID: "   + wifiLists.get(i).SSID);
                    mLevel.setText("Level: " + String.valueOf(wifiLists.get(i).level));
                    mFreq.setText("Freq: " + String.valueOf(wifiLists.get(i).frequency));
                }
            }
        super.onResume();
    }

for checking thing in period time you should use services in android. services are always run in background unless user stop service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM