如何从 android 中的扫描结果中过滤特定的 SSID?

How to filter a specific SSID from scan result in android?

我是 android 开发的新手,我正在开发一个应用程序,该应用程序扫描所有可用的 WI-FI,然后将它们显示在列表中,其工作正常,代码如下:

private var wifiManager: WifiManager? = null
private val arrayList = ArrayList<String>()
private var adapter: ArrayAdapter<*>? = null

private var wifiReceiver: BroadcastReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val results = wifiManager!!.scanResults
        unregisterReceiver(this)

        for (scanResult in results) {
            arrayList.add(scanResult.SSID)
            adapter!!.notifyDataSetChanged()

        }
    }
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
    adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList)

    val wifi = AlertDialog.Builder(this)
    wifi.setTitle("Wifi scan list")
    wifi.setAdapter(adapter) { dialog, which ->
    }
    wifi.create()
    wifi.show()

}

但现在我想从包含“_”的 wifi 扫描列表中隐藏一些 ssid。如何从 wifi 扫描列表中隐藏这些 SSID?

改成这样:

for (scanResult in results) {
    if (!scanResult.SSID.contains("_") {
        arrayList.add(scanResult.SSID)
        adapter!!.notifyDataSetChanged()
    }
}
  for (scanResult in results) {
     if(!scanResult.SSID.matches("(.*)_(.*)")) {
        arrayList.add(scanResult.SSID)
        adapter!!.notifyDataSetChanged()
        }
    }