public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_CONNECTED:
ble_state = true;
break;
case BluetoothAdapter.STATE_DISCONNECTED:
ble_state = false;
break;
}
이런식으로 연결상태를 읽어올 수 있는 거 아닌가요?
읽어와서 ble_state값에 따라서 Activity에 출력하고 싶은데... 상태를 읽어오지를 못하는 거 같네요..
Gatt설정은
if (mBleManager.connectGatt(mContext, true, address)) {
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
mConnectionInfo.setDeviceAddress(address);
mConnectionInfo.setDeviceName(device.getName());
}
Auto connect를 설정한 상태입니다.
Activtiy에서 Service실행중이면서 foreground를 사용중입니다.,