현재 BLE를 Service로 만들어두고
Fragment 내에 있는 특정 요소들을 클릭하면
Service에 등록된 BLE를 연결 및 연결끊기
BLE Scanning 그리고 fragment의 화면을 변경하는 등의 개발을 해야하는데
어떻게 구성해야할지 막막합니다 ㅠ
Service 를 상속받은 클래스 안에서 블루투스 어댑터나 스캐너, 매니저 등을 다 가지고 있는게 좋을까요?
Service와 Fragment 등이 통신하는 것 자체가 잘 이해가 안되는 것 같습니다 ㅠ
Fragment에 자원중에 before_connect에 클릭리스너를 만들어뒀는데요.
현재 서비스는 MainActivity에 만들어둔 상태입니다.
BLE 관련 연결 및 스캐닝 등의 함수는 BluetoothService 서비스에 만들어져 있는 상태입니다.
제가 하고 싶은 것은 fragment 안에 before_connect를 눌렀을 때
MainActivity에서 바인딩된 서비스의 함수인 connect또는 disconnect와 같은 함수를 실행하는건데요.
어떻게 접근할 수 있을까요 ㅠ
BluetoothService : Service
- startScaning() : bluetoothLeScanner.startScan() 실행
- connect() : bluetooth 기기 연결
- disconnect() : bluetooth 기기 연결 해제
- scanCallback, gattCallback
- setCharacteristicNotification() : writeDescriptor 실행
MainActivity : 현재는 여기서
var intent = Intent()
intent.setClass(this, BluetoothService::class.java)
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
이렇게 onCreate에 있습니다.
Fragment
- before_connect : 라는 아이디의 요소가 있고 onClickListener가 되어있습니다.
어떤식으로 동작하게 해야하는지 감이 잘 오지 않습니다 ..