Jak programowo rozpakować lub usunąć sparowane urządzenie bluetooth na Androidzie?
Projekt polega na użyciu mojego telefonu z Androidem do łączenia się z moimi urządzeniami arduino. ale jak Mogę rozpakować sparowane. Widzę, że lista sparowanych jest przechowywana, gdzie bluetoothadapter może pobrać w każdej chwili.
PS:
1st, wiem, że długie naciśnięcie sparowanego urządzenia rozpakuje go.
ale pytanie brzmi, Jak mogę to zrobić programowo?
2nd, sprawdziłem bluetoothdevice i bluetoothAdapter klasy, nie ma funkcji, aby to zaimplementować.
Dzięki.4 answers
Ten kod działa dla mnie.
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());
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-30 20:54:25
Rozpakuj wszystkie urządzenia:
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());
}
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-19 21:53:28
W klasie BluetoothService jest metoda removebond () do rozpakowywania , sparowania urządzeń. Na koniec ta metoda wywołuje rmovebondnative ().
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-15 09:30:54
Jeśli chcesz usunąć urządzenie bluetooth pary dla tego przede wszystkim trzeba rozpakować wszystkie urządzenia i następnie kliknij na opcję serch znajdziesz wszystkie urządzenia zostały usunięte z listy.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-20 01:37:53