diff --git a/src/android/BLECentralPlugin.java b/src/android/BLECentralPlugin.java index ec755343..ddc82b01 100644 --- a/src/android/BLECentralPlugin.java +++ b/src/android/BLECentralPlugin.java @@ -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) { diff --git a/src/android/Peripheral.java b/src/android/Peripheral.java index 43cddb5b..e6aed745 100644 --- a/src/android/Peripheral.java +++ b/src/android/Peripheral.java @@ -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; @@ -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; } @@ -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));