반응형
private val mBluetoothStateReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent!!.action //입력된 action
val intents: Intent = intent
val device = intents.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
Dlog.d( "action : $action")
//입력된 action에 따라서 함수를 처리한다
when (action) {
BluetoothAdapter.ACTION_STATE_CHANGED -> {
val state =
intents.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
when (state) {
BluetoothAdapter.STATE_OFF -> {
}
BluetoothAdapter.STATE_TURNING_OFF -> {
}
BluetoothAdapter.STATE_ON -> {
}
BluetoothAdapter.STATE_TURNING_ON -> {
}
}
}
BluetoothDevice.ACTION_ACL_CONNECTED -> {
isConnected = true
//mBluetoothAdapter!!.cancelDiscovery()
isScanning = false
Dlog.d( "onReceive: action_acl_connected")
}
BluetoothDevice.ACTION_BOND_STATE_CHANGED -> {
}
BluetoothDevice.ACTION_ACL_DISCONNECTED -> {
isConnected = false
isScanning = false
}
BluetoothAdapter.ACTION_DISCOVERY_STARTED -> {
BluetoothListener!!.startScan()
isScanning = true
}
BluetoothDevice.ACTION_FOUND -> {
// if (!isConnected) {
val device_name = device!!.name
val device_Address = device.address
val rssi =
intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE).toInt()
if (device_name != null && device_name.length > 0) {
Dlog.d( "====device_name : $device_name")
Dlog.d( "====device_Address : $device_Address")
Dlog.d( "====device_RSSI : $rssi")
if (device_name.contains("@@@@@") || device_name.contains("@@@@") /*&& rssi > -80*/) {
bluetooth_device.add(device)
BluetoothListener!!.findDevice(bluetooth_device)
//showBluetoothDeviceList()
}
}
// } else {
// stopScan()
// }
}
BluetoothAdapter.ACTION_DISCOVERY_FINISHED -> {
//블루투스 기기 검색 종료
BluetoothListener!!.scanFinished()
isScanning = false
}
BluetoothDevice.ACTION_PAIRING_REQUEST -> {
}
}
}
}
반응형
'Android' 카테고리의 다른 글
안드로이드 발전과정 (0) | 2023.02.05 |
---|---|
Android Https body 통신 로그 보기 (0) | 2022.10.27 |
Android DEBUG 모드 체크하기 / 디버그 모드일때만 로그 보이기 (0) | 2022.10.25 |
Android Release 모드에서 Log 보기 (0) | 2022.10.12 |
Android filesDir.path 폴더 안에 하위 목록까지 삭제하기 (0) | 2022.09.27 |
댓글