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

[Question] get Paired Devices #428

Open
BrunoEleodoro opened this issue Feb 21, 2020 · 12 comments
Open

[Question] get Paired Devices #428

BrunoEleodoro opened this issue Feb 21, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@BrunoEleodoro
Copy link

BrunoEleodoro commented Feb 21, 2020

Hello you all, firstly let me say that you guys did an awesome job creating this library, the example folder is helpful as well.

But I'm not sure where I can find how to get the Bonded devices (Paired ones), and how to connect to this devices?

Thanks a lot.

@dannyalbuquerque
Copy link

dannyalbuquerque commented Mar 4, 2020

@mikolak
Copy link
Collaborator

mikolak commented Mar 4, 2020

The iOS method is exposed as BleManager().connectedPeripherals().
I think it may not be possible to get them on Android at the moment, but it looks doable. I'll give you an update once I get to it.

@BrunoEleodoro
Copy link
Author

Thank you.

@mikolak @dannyalbuquerque

@mikolak mikolak added the enhancement New feature or request label Mar 4, 2020
@Peetz0r
Copy link

Peetz0r commented Mar 16, 2020

Ah, this explains why BleManager().connectedPeripherals() was giving me empty lists when I know it shouldn't on Android.

flutter_blue does it like this: https://github.com/pauldemarco/flutter_blue/blob/2ccdc68d474c158ae7cfbcae993e430a578173ec/android/src/main/java/com/pauldemarco/flutter_blue/FlutterBluePlugin.java#L173

@Ahmadre
Copy link

Ahmadre commented Jul 12, 2020

@Ahmadre
Copy link

Ahmadre commented Jul 12, 2020

I wrote a method in Java to handle fetching boundedDevices:

    @RequiresPermission(Manifest.permission.BLUETOOTH)
    private void getPairedDevices(@NonNull final MethodChannel.Result result) {
        Log.d(TAG, "Get paired devices");


        bleAdapter.getKnownDevices(deviceIdentifiers.toArray(new String[deviceIdentifiers.size()]) ,new OnSuccessCallback<Device[]>() {	        final SafeMainThreadResolver resolver = new SafeMainThreadResolver<>(new OnSuccessCallback<Device[]>() {
            @Override	            @Override
            public void onSuccess(Device[] devices) {	            public void onSuccess(Device[] devices) {
                Log.d(TAG, "Found known devices" + devices.length);	                try {
                resolver.onSuccess(devices);	                    result.success(devicesResultJsonConverter.toJson(devices));
                } catch (JSONException e) {
                    e.printStackTrace();
                    result.error(null, e.getMessage(), null);
                }
            }	            }
        }, new OnErrorCallback() {	        }, new OnErrorCallback() {
            @Override	            @Override
            public void onError(BleError error) {	            public void onError(BleError error) {
                resolver.onError(error);	                Log.e(TAG, "Get paired devices error " + error.reason + "  " + error.internalMessage);
                result.error(String.valueOf(error.errorCode.code), error.reason, bleErrorJsonConverter.toJson(error));
            }	            }
        });	        });

        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        List<Device> devices = new ArrayList<>();

        for (int i = 0; i < pairedDevices.size(); i++) {
            BluetoothDevice blDevice =  pairedDevices.iterator().next();
            Device device = new Device(blDevice.getAddress(), blDevice.getName());
            devices.add(device);
        }

        Log.d(TAG, "Found paired devices" + devices.size());
        resolver.onSuccess(devices);
    }	    
}

But I am getting an error from my forked Branch:

MissingPluginException(Noimplementation found for method getPairedDevices on channel flutter_ble_lib)

@mikolak
Copy link
Collaborator

mikolak commented Jul 12, 2020

@Ahmadre
You need to handle the method call in the plugin class: https://github.com/Polidea/FlutterBleLib/blob/develop/android/src/main/java/com/polidea/flutter_ble_lib/FlutterBleLibPlugin.java#L120
(same class name for iOS)

This issue has to be fixed in MultiPlatformBleAdapter, but we didn't have the time to take care of it yet.

@ChrisMarxDev
Copy link

Are there any updates on this? I'm currently in the situation that I need to get a device that could potentially already be paired with my android phone.

@mikolak
Copy link
Collaborator

mikolak commented Dec 11, 2020

Sorry, no updates yet. I finally have some time for the libraries, so work on FlutterBleLib and BLEmulator has started, but I'm unable to give you any timeline for this issue right now.

@kapibara91
Copy link

Same problem, hope update to can getting Paired Devices, thanks.

@nchsoft
Copy link

nchsoft commented Feb 5, 2021

Also need this functionality

@tohami
Copy link

tohami commented Apr 9, 2023

any updated regarding this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants