これは私が持っているコードです:
try {
String uuid = "116eadaf568c472a9ee799c6fb7dab9c";
Log.i(TAG, "BGC value NEW UUID: " + uuid);
boolean change = characteristic.setValue(URLEncoder.encode(uuid, "utf-8"));
Log.i(TAG, "BGC value after: " + characteristic.getValue() + " / has changed: " + change);
Log.i(TAG, "BGC value after: " + toHexadecimal(characteristic.getValue()) + " / has changed: " + change);
boolean statusWrite = gatt.writeCharacteristic(characteristic);
Log.i(TAG, "BGC value after statusWRITE: " + statusWrite);
} catch (Exception e) {
Log.e("", "BGC error is: " + e.getMessage());
}
StatusWrite は true を返します。同じコードを、NAME 特性の変更に使用します。どちらが変更されますか。ただし、UUID は同じままです。私は何を間違っていますか?PS: このタイプのビーコンを使用しています。
LightBlueアプリで試してみたところ、なんとか変更できましたがUUID
、確認したところ、特性は「書き込み可能」です
これは私が何かが間違っていると思うところです:
02-19 12:26:30.727: I/BEACON(24089): BGC value before before HEXA: [B@e20538b
02-19 12:26:31.381: I/BEACON(24089): BGC value before toHexa: 116eadaf568c472a9ee799c6fb7dab9c
02-19 12:26:43.925: I/BEACON(24089): BGC value NEW UUID: 916eadaf568c472a9ee799c6fb7dab9c
02-19 12:26:44.987: I/BEACON(24089): BGC value after: [B@57b4ac / has changed: true
02-19 12:26:54.826: I/BEACON(24089): BGC value after: 3931366561646166353638633437326139656537393963366662376461623963 / has changed: true
したがって、変更する前に値を取得していることがわかります。これは、現在の UUID[B@e20538b
に変換されます。116eadaf568c472a9ee799c6fb7dab9c
この後、916eadaf568c472a9ee799c6fb7dab9c
I ask for the value again:に変更します[B@57b4ac
。しかし、toHexadecimal(value)
取得する代わりに同じことを行うと、次のようになります: 矛盾の理由は?
これは「toHexadecimal」です:
private static String toHexadecimal(byte[] digest) {
String hash = "";
for (byte aux : digest) {
int b = aux & 0xff;
if (Integer.toHexString(b).length() == 1) hash += "0";
hash += Integer.toHexString(b);
}
return hash;
}
編集:
値を変更する前とこの後に追加しました:
Log.i(TAG, "BGC value before before HEXA new String: " + new String(characteristic.getValue(), "UTF-8"));
boolean change = characteristic.setValue(uuid.getBytes());
Log.i(TAG, "BGC value after new String: " + new String(characteristic.getValue(), "UTF-8") + " / has changed: " + change);
そして、これを返します:
02-19 14:12:41.140: I/BEACON(12090): BGC value before before HEXA new String: n��V�G*����}��
02-19 14:12:41.141: I/BEACON(12090): BGC value after new String: 1111 / has changed: true
値を設定する方法が明らかに間違っているように感じますが、以前にヘックスなどに変換する必要がありますか? 理解できません
また、バイトの配列を記録しました。初期値は次のとおりです。
02-19 14:21:46.059: I/BEACON(21134): BGC value before before HEXA byte array: [17, 110, -83, -81, 86, -116, 71, 42, -98, -25, -103, -58, -5, 125, -85, -100]
ここでは、文字列 UUID を既に設定されている値と同じ値に変更しました。バイト配列を作成すると、次のようになります。
02-19 14:21:46.060: I/BEACON(21134): BGC value after byte array: [49, 49, 54, 101, 97, 100, 97, 102, 53, 54, 56, 99, 52, 55, 50, 97, 57, 101, 101, 55, 57, 57, 99, 54, 102, 98, 55, 100, 97, 98, 57, 99] / has changed: true
まったく同じ文字列に 2 つの異なるバイト配列を含めるにはどうすればよいですか? また、最初のものには多くのものが含まれていることに気づきました-、これはいいえ、なぜですか?