Eddystone ベースのアプリを開発しようとしています。Google のサンプル コードを取得して、変更してみました。Android の仕様によると、サービス データの最大長は 31 バイトです。
次のコード buildServiceData() でサービスデータの長さを変更してみました
ここでは最大で 20 バイトのみを受け入れます。それ以上 (例: 21 バイト) ADVERTISE_FAILED_DATA_TOO_LARGE エラーが発生する
//error
Class: AdvertiseCallback
Error : ADVERTISE_FAILED_DATA_TOO_LARGE
ブロードキャストするアドバタイズ データが 31 バイトを超えているため、アドバタイズを開始できませんでした。
UID フレームを使用してロリポップ デバイスでテストしています。
私が間違っていることを教えてください。
byte[] serviceData = null;
// 1+1+10+6+1+1+1 = 21 bytes
private byte[] buildServiceData() throws IOException {
byte txPower = txPowerLevelToByteValue();
byte[] namespaceBytes = toByteArray(namespace.getText().toString());
byte[] instanceBytes = toByteArray(instance.getText().toString());
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write(new byte[]{FRAME_TYPE_UID, txPower});
os.write(namespaceBytes);
os.write(instanceBytes);
//for testing only
// os.write(new byte[]{txPower});
// os.write(new byte[]{txPower});
// os.write(new byte[]{txPower});
return os.toByteArray();
}
//advertise the data
AdvertiseData advertiseData = new AdvertiseData.Builder()
.addServiceData(SERVICE_UUID, serviceData)
.addServiceUuid(SERVICE_UUID)
.setIncludeTxPowerLevel(false)
.setIncludeDeviceName(false)
.build();
namespace.setError(null);
instance.setError(null);
setEnabledViews(false, namespace, instance, rndNamespace, rndInstance, txPower, txMode);
adv.startAdvertising(advertiseSettings, advertiseData, advertiseCallback);