.getScanResults()返回相同的对象

时间:2017-07-19 22:54:32

标签: android wifimanager

我遇到一个问题,当我调用“.getScanResults()”时,返回列表中的对象是相同的。我已对此进行了测试并记录了结果以进行演示。

  

SSID:####,BSSID:c0:c1:c0:ab:42:dc,能力:[WEP] [ESS],级别:-51,频率:2412,时间戳:246825251245

     

SSID:####,BSSID:c0:c1:c0:ab:42:dc,能力:[WEP] [ESS],级别:-51,频率:2412,时间戳:246825251245

包括时间戳在内的所有内容都完全相同。我的代码如下。

public void checkNetwork(View view) {
    wifi_manager.startScan();

    WifiScanReceiver wifiReciever = new WifiScanReceiver();
    registerReceiver(wifiReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}

class WifiScanReceiver extends BroadcastReceiver {
    public void onReceive(Context c, Intent intent) {
        if (intent.getAction() == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {

            List<ScanResult> wifi_scan_list = wifi_manager.getScanResults();

            int number_of_access_points = wifi_scan_list.size();

            for(int i = 0; i < number_of_access_points; i++) {
                String data = wifi_scan_list.get(i).toString();

                writeToFile(data + System.getProperty("line.separator"));
            }

            wifi_scan_list.clear();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试替换

library(shiny)
 ui <- fluidPage(
  fileInput(inputId = "up","", accept = '.csv'),
  uiOutput("sliders")
)

server <- function(input, output, session) {

  INPUT <- reactive({
    infile <- input$up
    if (is.null(infile))
      return(NULL)
    read.csv(infile$datapath, header = TRUE, sep = ",")
  })

 inVars <- reactive({
    unique(INPUT()$Big)
  })

  output$sliders <- renderUI({
    pvars <- length(inVars())
    if (pvars > 0) {
      div(
        lapply(seq(pvars), function(i) {
          numericInput(inputId = paste0("range", inVars()[i]),label = inVars()[i],value = 1)
        }),
        actionButton("getValues", "Get values"),
        tableOutput('table')
      )
    }
  })

  values <- 0

  # get the values of each numericInput and store them in "values"
  observeEvent(input$getValues, {
      # initialize vector 
      values <<- rep(NA, length(inVars()))
      names(values) <<- inVars()

      for(k in 1:length(inVars())) { 
        inputName <- paste0("range", inVars()[k])
        # only get a value if the numeric input exists
        if (!is.null(inputName))
          values[[k]] <<- input[[inputName]]
      }
    # show values as a table
    output$table <- renderTable(data.frame(
                        variable = inVars(),
                        values))

  })

}

shinyApp(ui = ui, server = server)

num,Big
1,a
2,a
3,b
4,b
5,c
6,c
7,d
8,d

此代码:

  1. 检索扫描结果的原始列表;
  2. creates a new HashSet并将所有原始扫描结果添加到该集合(从而删除重复项);
  3. creates a new ArrayList仅包含经过重复数据删除的扫描结果。
  4. 如果不对此进行测试,我无法100%确定原始列表的顺序将保留在最终列表中;但是,从你的其余代码来看,这似乎对你的用例并不重要。