I call on my bluetooth adapter mBluetoothAdapter.startDiscovery(); which then returns me a list of BluetoothDevices. When I click on 1 of these devices, I do this:
mBluetoothGatt = bluetoothDevice.connectGatt(MainActivity.this, false, mGattCallback);
Where is my callback:
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { mConnectionState = STATE_CONNECTED; Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices()); List<BluetoothGattService> listBGS = mBluetoothGatt.getServices(); Log.i("","list size: " + listBGS.size()); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; Log.i(TAG, "Disconnected from GATT server."); } } @Override // New services discovered public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { Log.w(TAG, "onServicesDiscovered GATT_SUCCESS: " + status); List<BluetoothGattService> listBGS = mBluetoothGatt.getServices(); Log.i("","list size: " + listBGS.size()); } else { Log.w(TAG, "onServicesDiscovered received: " + status); } } @Override // Result of a characteristic read operation public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { Log.w(TAG, "onCharacteristicRead GATT_SUCCESS: " + status + " / char: " + characteristic); } } };
Now when I try to use it on phones, I get STATE_CONNECTED on onConnectionStateChange and then call DiscoverServices and I return GATT_SUCCESS onServicesDiscoveres. Therefore, I can take uuids from my services. BUT, when I try this on the lighthouse, I return STATE_CONNECTED, and when I call DiscoverServices, I return the status code: 129 β GATT_INTERNAL_ERROR Why does this happen for my lighthouses? Is there any other way how can I use uuid devices? I just need a UUID to be able to do this afterwards for beaconManager:
try { beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null)); } catch (RemoteException e) { }
EDIT
I know that the lighthouse should ask me to enter the code, but this is not so. What for? I tried to add this code:
final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter);
But still I do not receive a request to pair and enter my passkey
This is my paired RequestReceiver:
private final BroadcastReceiver mPairingRequestRecevier = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (BluetoothDevice.ACTION_PAIRING_REQUEST.equals(intent.getAction())) { final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, BluetoothDevice.ERROR); if (type == BluetoothDevice.PAIRING_VARIANT_PIN) { device.setPin(intToByteArray(123456)); abortBroadcast(); } else { Log.e("","Unexpected pairing type: " + type); } } } };