Skip to content

Commit

Permalink
Android: update local name during scan as suggested by murilommp
Browse files Browse the repository at this point in the history
see also:
* don#995
  • Loading branch information
akrcc committed Dec 12, 2023
1 parent 073c80d commit 2a8ba9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/android/BLECentralPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ public void onScanResult(int callbackType, ScanResult result) {
isConnectable = result.isConnectable();
}

Peripheral peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(), isConnectable);
Peripheral peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(), result.getScanRecord().getDeviceName(), isConnectable);
peripherals.put(device.getAddress(), peripheral);

if (discoverCallback != null) {
Expand Down
10 changes: 8 additions & 2 deletions src/android/Peripheral.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Peripheral extends BluetoothGattCallback {

private BluetoothDevice device;
private byte[] advertisingData;
private String advertsingName = null;
private Boolean isConnectable = null;
private int advertisingRSSI;
private boolean autoconnect = false;
Expand Down Expand Up @@ -84,10 +85,11 @@ public Peripheral(BluetoothDevice device) {

}

public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, Boolean isConnectable) {
public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, String advertsingName, Boolean isConnectable) {
this.device = device;
this.advertisingRSSI = advertisingRSSI;
this.advertisingData = scanRecord;
this.advertsingName = advertsingName;
this.isConnectable = isConnectable;
}

Expand Down Expand Up @@ -271,7 +273,11 @@ public JSONObject asJSONObject() {
JSONObject json = new JSONObject();

try {
json.put("name", device.getName());
if (this.advertsingName != null) {
json.put("name", this.advertsingName);
} else {
json.put("name", device.getName());
}
json.put("id", device.getAddress()); // mac address
if (advertisingData != null) {
json.put("advertising", byteArrayToJSON(advertisingData));
Expand Down

0 comments on commit 2a8ba9c

Please sign in to comment.