Ich versuche, in NEXUS 9 zu werben und den Fehler ADVERTISE_FAILED_DATA_TOO_LARGE zu bekommen. Es funktionierte völlig in Ordnung, wenn ich den Dienst nach der erfolgreichen Werbung für das Hinzufügen, aber wenn ich den Dienst über Werbung Daten Builder hinzufügen, so dass andere Geräte beim Scannen filtern kann ich Fehlercode 1, dh ADVERTISE_FAILED_DATA_TOO_LARGEBluetooth Peripheriegerät ADVERTISE_FAILED_DATA_TOO_LARGE
a) Arbeits-Code erhalten
public void startAdvertisingService() {
AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
.setTimeout(0)
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
.build();
AdvertiseData.Builder advertiseData = new AdvertiseData.Builder();
advertiseData.setIncludeDeviceName(true);
BluetoothLeAdvertiser myBluetoothLeAdvertiser = btAdapter.getBluetoothLeAdvertiser();
myBluetoothLeAdvertiser.stopAdvertising(mAdvertiseCallback);
myBluetoothLeAdvertiser.startAdvertising(settings, advertiseData.build(),mAdvertiseCallback);
}
private AdvertiseCallback mAdvertiseCallback = new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
BLEBroadcast();
}
@Override
public void onStartFailure(int errorCode) {
String description = "";
if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED)
description = "ADVERTISE_FAILED_FEATURE_UNSUPPORTED";
else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS)
description = "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS";
else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED)
description = "ADVERTISE_FAILED_ALREADY_STARTED";
else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE)
description = "ADVERTISE_FAILED_DATA_TOO_LARGE";
else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR)
description = "ADVERTISE_FAILED_INTERNAL_ERROR";
else description = "unknown";
}
};
und Zugabe auch den Service:
void BLEBroadcast() {
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(characteristicUUID, BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE);
BluetoothGattDescriptor desc = new BluetoothGattDescriptor(descriptorUUID, BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE);
desc.setValue("".getBytes());
characteristic.addDescriptor(desc);
BluetoothGattService service = new BluetoothGattService(serviceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
service.addCharacteristic(characteristic);
mGattServer.addService(service);
}
b) arbeitet nicht, wenn Service zunächst Zugabe, so dass durch zentrale durch~~POS=TRUNC filte entdeckt werden können r:
Aufruf BLEBroadcast()
Funktion vor startAdvertisingService()
Aufruf und auch das Hinzufügen
AdvertiseData.Builder advertiseData = new AdvertiseData.Builder();
advertiseData.addServiceUuid(new ParcelUuid(serviceUUID));
gibt Werbe-Ausfall mit dem Fehlercode 1.
Können Sie Ihre Frage ändern, um (a) den Code anzuzeigen, der "völlig in Ordnung" funktioniert, und (b) den Code, der nicht funktioniert? Es ist nicht klar, was sich geändert hat. – davidgyoung
@davidgyoung Ich habe meine Frage bearbeitet, hoffe du kannst mich jetzt holen. – Shubham