मैं नेक्सस 9 में विज्ञापन करने और ADVERTISE_FAILED_DATA_TOO_LARGE की त्रुटि प्राप्त करने का प्रयास कर रहा हूं। यह बिल्कुल ठीक है जब मैं सफलतापूर्वक के बाद सेवा को जोड़ने था विज्ञापन कर लेकिन अगर मैं सेवा जोड़ने के माध्यम से डाटा बिल्डर विज्ञापन काम कर रहा था ताकि अन्य उपकरणों फ़िल्टर कर सकते हैं, जबकि स्कैनिंग, मैं त्रुटि कोड प्राप्त 1 यानी ADVERTISE_FAILED_DATA_TOO_LARGEब्लूटूथ परिधीय ADVERTISE_FAILED_DATA_TOO_LARGE
एक) वर्किंग कोड
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);
}
ख) जब सेवा शुरू में जोड़ने ताकि filte के माध्यम से केंद्रीय द्वारा की खोज की जा सकती है, काम नहीं:
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";
}
};
और भी सेवा को जोड़ने r:
startAdvertisingService()
बुला और भी जोड़ने से पहले BLEBroadcast()
समारोह बुला
AdvertiseData.Builder advertiseData = new AdvertiseData.Builder();
advertiseData.addServiceUuid(new ParcelUuid(serviceUUID));
त्रुटि कोड के साथ विज्ञापन विफलता देता 1.
क्या आप अपना प्रश्न संशोधित कर सकते हैं (ए) कोड जो "पूरी तरह से ठीक" काम करता है, और (बी) कोड जो काम नहीं करता है? यह स्पष्ट नहीं है कि क्या बदल गया। – davidgyoung
@davidgyoung मैंने अपना प्रश्न संपादित किया, आशा है कि अब आप मुझे प्राप्त कर सकते हैं। – Shubham