티스토리 뷰
[MainActivity]
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
// Check if device supports Bluetooth
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
// Device supports Bluetooth
// Check if Bluetooth is enabled on device
if (!bluetoothAdapter.isEnabled) {
// Request to enable Bluetooth
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}
// Start scanning for nearby Bluetooth devices
bluetoothAdapter.startDiscovery()
// Register for broadcast of discovered devices
val filter = IntentFilter(BluetoothDevice.ACTION_FOUND)
registerReceiver(receiver, filter)
}
// BroadcastReceiver to handle discovered devices
val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action: String = intent.action
if (BluetoothDevice.ACTION_FOUND == action) {
val device: BluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)
// Do something with discovered device
}
}
}
[AndroidManifest.xml]
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
반응형
'SWDesk > App' 카테고리의 다른 글
| [Kotlin] Nano33 IoT 기기와 데이터 통신하기 (2) | 2023.02.20 |
|---|---|
| [Kotlin] Nano33 IoT 기기에 "Hello" 보내기 (0) | 2023.02.17 |
| [Python] msedge 드라이버 및 모듈 설치 (0) | 2022.09.03 |
| [Android] 테두리 만들기 (0) | 2021.11.28 |
| Testing BLE for FamGam (0) | 2021.11.19 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Innovations
- 치매
- 빌리언트
- 절연형
- image
- Video
- 혁신과허들
- 치매방지
- Innovations&Hurdles
- 심심풀이
- 허들
- 오블완
- bilient
- 티스토리챌린지
- 아두이노
- Innovation&Hurdles
- 심심풀이치매방지기
- 배프
- 전압
- 둎
- 전류
- BSC
- Decorator
- ServantClock
- 빌리칠드
- arduino
- DYOV
- 혁신
- Hurdles
- BiliChild
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함

