我必须获得以毫秒为单位的广告间隔。我使用了 result.periodicAdvertisingInterval
但这返回 0。我必须实现这样的东西:
private val scanCallback = object : ScanCallback(){
@RequiresApi(Build.VERSION_CODES.N)
@SuppressLint("MissingPermission", "NotifyDataSetChanged")
override fun onScanResult(callbackType: Int, result: ScanResult) {
val scanJob = CoroutineScope(Dispatchers.Main).launch {
val tag = deviceMap.computeIfAbsent(result.device.address) {
val newTag = BleTag(result.device.name ?: "Unbekannt", result.device.address, result.rssi , result.scanRecord?.bytes, "")
deviceList.add(newTag)
newTag
}
tag.name = result.device.name ?: "Unbekannt"
tag.rssi = result.rssi
tag.advertisementData = result.scanRecord?.bytes
}
deviceList.sortBy {result.rssi }
recyclerView.adapter?.notifyDataSetChanged()
menu.findItem(R.id.count).title = "Geräte: " + deviceList.size
super.onScanResult(callbackType, result)
}
override fun onScanFailed(errorCode: Int) {
super.onScanFailed(errorCode)
Log.e("Scan failed","")
}
}
最佳答案
这个结果是减去 timestamps 得到的。同一设备的两个连续广告。
关于java - 蓝牙 LE - 如何获得广告间隔(以毫秒为单位)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74011557/