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

时间:2018-12-24 14:19:45

标签: java android kotlin android-wifi wifimanager

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

self.on_init()

但是现在我想从包含“ 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?

2 个答案:

答案 0 :(得分:1)

只需更改为此:

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

答案 1 :(得分:1)

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