Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 스크롤뷰 자식 뷰 높이 동적조절
- 레트로핏 MVVM
- dialog fragment
- NestedScrollView
- lifecycleScope
- 뷰바인딩
- 레트로핏2
- 데이터바인딩
- ScrollView Child View Height Programmatically
- Android
- 프로그래머스
- 안드로이드
- 쉐어드
- dialog resize
- 리사이클러뷰
- java
- 위치정보확인
- DataBinding
- viewBinding
- Retrofit Kotlin
- 레트로핏 코틀린
- programmers
- 다이얼로그 프래그먼트
- location System
- recyclerview
- 다이얼로그 크기조절
- 인텐트란?
- ScrollView with ConstraintLayout
- Retrofit with MVVM
- dialogfragment singleton
Archives
- Today
- Total
안드로이드 세계
[Android] BluetoothDevice 현재 연결상태확인 본문
BlueTooth가 앱이 켜진 후 연결되는건 잘감지가되지만, 이미 연결된 장치가 있는지 여부에 대해서 알 필요가 있었다.
구글링을 통해 알게되었는데, Method방식을 이용하였다.
public boolean isConnected(BluetoothDevice device) {
try {
Method m = device.getClass().getMethod("isConnected", (Class[]) null);
boolean connected = (boolean) m.invoke(device, (Object[]) null);
return connected;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
연결되어있는 장치가 있다면 true를 없다면 false를 반환한다.
해당 방식은 페어링된 장치중 연결된 장비가있는지 여부를 확인하는 방법이다.
public void PairingBluetoothListState(){
try{
Set<BluetoothDevice> bluetoothDevices = BluetoothAdapter.getDefaultAdapter().getBondedDevices();
for (BluetoothDevice bluetoothDevice : bluetoothDevices) {
if (isConnected(bluetoothDevice)) {
//TODO : 연결중인상태
}else{
//TODO : 연결중이 아닌상태
}
}
}catch(NullPointExecption e){
//블루투스 서비스 사용불가인 경우
}
}
How to programmatically tell if a Bluetooth device is connected?
I understand how to get a list of paired devices but how can I tell if they are connected? It must be possible since I see them listed in my phone's Bluetooth device list and it states their conn...
stackoverflow.com