我正在尝试在Android L上创建广告客户,而我的其他Android设备正在扫描该设备并尝试与其建立连接。
但是每当我拨打connectGatt
时,我都会在gatt回拨中获得BluetoothProfile.STATE_DISCONNECTED
。
这就是我创建广告的方式
// 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);
答案 0 :(得分:0)
因为我无法发表评论但是试着让它成为一个答案。
在您的示例中,我只看到广告已启用。但是,要提供GATT服务,您还需要创建一个处理请求的GATT服务器。
祝你好运!