I am trying to create a advertiser on Android L and my other android device is scanning that device and trying to make a connection with it.
but every time i call connectGatt
i am getting BluetoothProfile.STATE_DISCONNECTED
in gatt callback.
this is how i have created the advertisement
// advertisement settings
AdvertiseSettings.Builder builderSetting= new AdvertiseSettings.Builder();
builderSetting.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
builderSetting.setConnectable(true);
builderSetting.setTimeout(0);
builderSetting.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
//advertisement data
AdvertiseData.Builder builderData = new AdvertiseData.Builder();
builderData.addServiceUuid(new
ParcelUuid(UUID.fromString("00002a29-0000-1000-8000-00805f9b34fb")));
byte mServiceData[] =
{ (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04 };
// i tried with addding service data
builderData.addServiceData(new
ParcelUuid(UUID.fromString("00002a29-0000-1000-8000-00805f9b34fb")), mServiceData);
//start advertising
mBTAdvertiser.startAdvertising(
builderSetting.build(),
builderData.build(), mAdvCallback);
Since i can't comment yet ill try to make it an answer.
In your example i only see the Advertising enabled. However to offer GATT services, you also need to create a GATT-server which handles the requests.
Check out the documentation to BluetoothManager.openGattServer(...).
Good luck!