How can i scanning the mobile phone's bluetooth by using bluetoothLescanner?

醉酒当歌 提交于 2020-01-25 07:25:14

问题


I asked this question a few hours ago, but I still can't solve it.

I'm trying to catch the BLE signal, and get the rssi vlue by using "BluetoothLeScanner" to measure the distance between two phone.

But, my program detects every BLE_signal except the Bluetooth signal on my phone.

The following is what I printed out with Log.e as I ran the program.

'''

2019-12-01 00:21:16.319 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 33:DC:55:32:73:96, rssi: -88, distance: 8.912509381337454
2019-12-01 00:21:16.949 22089-22089/com.example.bluetooth E/get_RSSI:          
name: null, addr: 33:DC:55:32:73:96, rssi: -92, distance: 14.12537544622754
2019-12-01 00:21:16.962 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -45, distance: 0.06309573444801933
2019-12-01 00:21:17.054 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 33:DC:55:32:73:96, rssi: -92, distance: 14.12537544622754
2019-12-01 00:21:17.064 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -45, distance: 0.06309573444801933
2019-12-01 00:21:17.661 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -49, distance: 0.1
2019-12-01 00:21:18.408 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -42, distance: 0.04466835921509631
2019-12-01 00:21:18.425 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 33:DC:55:32:73:96, rssi: -87, distance: 7.943282347242816
2019-12-01 00:21:19.148 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -48, distance: 0.08912509381337455
2019-12-01 00:21:19.779 22089-22089/com.example.bluetooth E/get_RSSI:  
name: null, addr: 22:32:AA:BF:25:16, rssi: -46, distance: 0.0707945784384138

and below is the MainActivity, onResume() & class Bluetooth2

override fun onResume() {
    super.onResume()
    val mBlueToothAdapter = BluetoothAdapter.getDefaultAdapter()
    val mBLEScanner = mBlueToothAdapter.getBluetoothLeScanner()
    Bluetooth2().initialize(mBLEScanner)
    }

...

class Bluetooth2 {

val mScanCallback = object: ScanCallback(){
override fun onScanResult(callbackType: Int, result: ScanResult?) {
        super.onScanResult(callbackType, result)
        val RSSI = result?.rssi
        val NAME = result?.device?.name
        val ADDR = result?.device?.address

        if(!BLE_DB().contains(ADDR)) {
            val text = "$ADDR $RSSI"
            BLE_DB().append(1, text)
            BLE_DB().append(2, NAME)
        }

        Log.e("get_RSSI", " name: $NAME, addr: $ADDR, rssi: $RSSI, distance: ${rssiTodis(RSSI)}")
    }
}
.
.
.

fun initialize(bluetoothLeScanner: BluetoothLeScanner){
    BLE_DB().initialize()
    bluetoothLeScanner.startScan(mScanCallback)
    Log.e("Initialization", "Initialized")

}

...

'''

I don't know why it doesn't catch the phone's signal...

Please help me...

  • enter image description here

  • enter image description here

Picture 1 is a screenshot of the Bluetooth window when I run Bluetooth. And Picture 2 is an existing RSSI analyzer application. As you can see in the pictures, my phone can scan my Galaxy S7 phone and recognize it, but I can't see it in my program's log. What should I do?

来源:https://stackoverflow.com/questions/59122163/how-can-i-scanning-the-mobile-phones-bluetooth-by-using-bluetoothlescanner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!