티스토리 뷰
[MainActivity]
val deviceAddress = "00:00:00:00:00:00" // Replace with the address of your Bluetooth device
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)
}
// Get the Bluetooth device by its address
val device: BluetoothDevice = bluetoothAdapter.getRemoteDevice(deviceAddress)
// Create a Bluetooth socket
val socket: BluetoothSocket = device.createRfcommSocketToServiceRecord(MY_UUID)
// Connect to the device
try {
socket.connect()
// Connection successful, do something with the socket
} catch (e: IOException) {
// Connection failed, handle the error
}
}
반응형
'SWDesk > App' 카테고리의 다른 글
| 명함 이미지에서 명함 데이터를 추출하는 앱 (1) | 2023.03.18 |
|---|---|
| 앱에서 생성된 데이터를 카카오톡으로 보내는 소스 코드 (0) | 2023.03.04 |
| 웹뷰 내 사용자 클릭 결과를 처리하기 위한 자바 소스 코드 (0) | 2023.02.26 |
| [Kotlin] 블루투스 페어링을 위한 소스 코드 (0) | 2023.02.23 |
| [Kotlin] Nano33 IoT 기기와 데이터 통신하기 (2) | 2023.02.20 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 티스토리챌린지
- 심심풀이치매방지기
- DYOV
- Innovation&Hurdles
- Innovations&Hurdles
- Hurdles
- 아두이노
- 오블완
- Video
- bilient
- Decorator
- 둎
- 전류
- 심심풀이
- arduino
- BSC
- image
- 배프
- 빌리언트
- 전압
- 허들
- 혁신과허들
- 절연형
- 빌리칠드
- 치매방지
- 치매
- Innovations
- 혁신
- ServantClock
- 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 |
글 보관함

