在Android中从wifi卡读取的间隔时间

时间:2014-05-20 09:19:51

标签: android wifi

我想问一下WifiReceiver类。 我正在使用下面的自定义类来读取rssi值,

此类每500毫秒调用一次,但它每4秒左右返回一次数据(非空字符串)。 我的应用程序每1秒需要一个新的rssi值...我该怎么做?

public class WirelessNetworks 
{
        private static WifiManager wifi;
        private static List<ScanResult> results;
        private static ArrayList<HashMap<String, String>> arraylist;
        private static String AllReadings;
        static WifiReceiver  receiverWifi;


        public static String FindSpesificNetworks() 
        {
            wifi.startScan();
            return AllReadings;
        }


        public static void Initial(Context context)
        {
            wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            receiverWifi=new WifiReceiver();
            context.registerReceiver(receiverWifi, 
                    new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        }



        public static class WifiReceiver extends BroadcastReceiver
        {
            @Override
            public void onReceive(Context context, Intent intent) 
            {
                AllReadings = new String();

                results=wifi.getScanResults();

                int size = results.size()-1;

                while (size >= 0) 
                {
                    String MAC = results.get(size).BSSID;
                    String RSSI = String.valueOf(results.get(size).level);
                    // Save MAC and RSSI as string in allreadings    
                    size--;
                }

            }           
        }
    }

1 个答案:

答案 0 :(得分:0)

额外延迟是由于处理时间...总时间是延迟和处理延迟之和。