繁体   English   中英

Bluetooth LE - 如何获得以毫秒为单位的广告间隔?

[英]Bluetooth LE - How do i get Advertisement Interval in milliseconds?

我必须以毫秒为单位获取广告间隔。 我使用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","")
    }
}

这个结果是通过减去同一设备的两个连续广告的时间戳获得的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM