Cómo descomprimir o eliminar dispositivo bluetooth emparejado mediante programación en Android?


El proyecto es usar mi teléfono android para conectar con mis dispositivos arduino. pero cómo puedo desenmarañar los emparejados. Veo que parece que la lista emparejada se almacena donde bluetoothadapter podría recuperar en cualquier momento.

PS: 1st, sé que el dispositivo emparejado de pulsación larga lo desenmarañará.
pero la pregunta aquí es ¿cómo puedo hacer que esto suceda programáticamente?

2do, he comprobado bluetoothdevice y BluetoothAdapter clase, no hay ninguna función para implementar esto.

Gracias.

Author: Soo Wei Tan, 2012-03-07

4 answers

Este código funciona para mí.

private void pairDevice(BluetoothDevice device) {
    try {
        if (D)
            Log.d(TAG, "Start Pairing...");

        waitingForBonding = true;

        Method m = device.getClass()
            .getMethod("createBond", (Class[]) null);
        m.invoke(device, (Object[]) null);

        if (D)
            Log.d(TAG, "Pairing finished.");
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

private void unpairDevice(BluetoothDevice device) {
    try {
        Method m = device.getClass()
            .getMethod("removeBond", (Class[]) null);
        m.invoke(device, (Object[]) null);
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}
 57
Author: Dev Perfecular,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-30 20:54:25

Desvincular todos los dispositivos:

Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        if (pairedDevices.size() > 0) {
            for (BluetoothDevice device : pairedDevices) {
                try {
                    Method m = device.getClass()
                            .getMethod("removeBond", (Class[]) null);
                    m.invoke(device, (Object[]) null);
                } catch (Exception e) {
                    Log.e("Removing has been failed.", e.getMessage());
                }
            }
        }
 10
Author: Péter Hidvégi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-19 21:53:28

En la clase BluetoothService hay método removebond() para desvincular , dispositivos emparejados. Finalmente este método llama a rmovebondnative ().

 1
Author: chandan kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-15 09:30:54

Si desea eliminar el dispositivo bluetooth par para esto en primer lugar, tiene que desenmarañar todo el dispositivo y luego haga clic en la opción serch encontrará que todo el dispositivo se ha eliminado de la lista.

 -5
Author: Bhuvn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-20 01:37:53