Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RSSI to result when discovering devices #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void list(Promise promise) {
Set<BluetoothDevice> bondedDevices = mBluetoothAdapter.getBondedDevices();

for (BluetoothDevice rawDevice : bondedDevices) {
WritableMap device = deviceToWritableMap(rawDevice);
WritableMap device = deviceToWritableMap(rawDevice, null);
deviceList.pushMap(device);
}
}
Expand Down Expand Up @@ -525,14 +525,17 @@ private void sendEvent(String eventName, @Nullable WritableMap params) {
* Convert BluetoothDevice into WritableMap
* @param device Bluetooth device
*/
private WritableMap deviceToWritableMap(BluetoothDevice device) {
private WritableMap deviceToWritableMap(BluetoothDevice device, Integer rssi) {
if (D) Log.d(TAG, "device" + device.toString());

WritableMap params = Arguments.createMap();

params.putString("name", device.getName());
params.putString("address", device.getAddress());
params.putString("id", device.getAddress());
if (rssi != null) {
params.putInt("rssi", rssi);
}

if (device.getBluetoothClass() != null) {
params.putInt("class", device.getBluetoothClass().getDeviceClass());
Expand Down Expand Up @@ -650,7 +653,8 @@ public void onReceive(Context context, Intent intent) {

if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
WritableMap d = deviceToWritableMap(device);
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
WritableMap d = deviceToWritableMap(device, rssi);
unpairedDevices.pushMap(d);
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
if (D) Log.d(TAG, "Discovery finished");
Expand Down