String essidPrefix = MainFragment.configuration.getEssidPrefix();
wifiManager.startScan();
results = wifiManager.getScanResults();
for(ScanResult scanResult : results){
String scanWifi = scanResult.SSID;
if(scanWifi.startsWith(essidPrefix)){
bssid = scanResult.BSSID;
//bssid now has two strings, abc123 and abc1234 for example
}
}
//bssid here only returns abc123
return bssid;
如代码所示,如何将 scanResults.BSSID
中的 abc123
和 abc1234
连接在一起,以便我能够返回它作为一个字符串?
最佳答案
如果我收到你的问题。
Java/Android中的字符串连接..
bssid = bssid+","+scanResult.BSSID; // comma separate
编辑
根据评论..您需要重置它。 bssid = "";
所以你的代码将如下所示。
List<String> ids = new ArrayList<String>();
String essidPrefix = MainFragment.configuration.getEssidPrefix();
wifiManager.startScan();
results = wifiManager.getScanResults();
bssid = ""; // this will reset it
for(ScanResult scanResult : results){
String scanWifi = scanResult.SSID;
if(scanWifi.startsWith(essidPrefix)){
// if you want to avoid null
ids.add(scanResult.BSSID); // comma separate
}
}
//bssid here only returns abc123
return bssid = android.text.TextUtils.join(",", ids);
关于java - ScanResults 用两个字符串设置我的变量,但返回值只有一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52510367/