diff --git a/app/src/main/java/me/aflak/libraries/ScanActivity.java b/app/src/main/java/me/aflak/libraries/ScanActivity.java index ffa5fae..16a3a5f 100644 --- a/app/src/main/java/me/aflak/libraries/ScanActivity.java +++ b/app/src/main/java/me/aflak/libraries/ScanActivity.java @@ -190,6 +190,11 @@ public void onDeviceUnpaired(BluetoothDevice device) { public void onError(int errorCode) { } + + @Override + public void onPairingFailed(BluetoothDevice device) { + + } }; private void startChatActivity(BluetoothDevice device){ diff --git a/bluetooth/src/main/java/me/aflak/bluetooth/Bluetooth.java b/bluetooth/src/main/java/me/aflak/bluetooth/Bluetooth.java index 7ea423b..4ece34e 100644 --- a/bluetooth/src/main/java/me/aflak/bluetooth/Bluetooth.java +++ b/bluetooth/src/main/java/me/aflak/bluetooth/Bluetooth.java @@ -674,6 +674,16 @@ public void run() { } }); } + } else if (state == BluetoothDevice.BOND_NONE && prevState == BluetoothDevice.BOND_BONDING) { + context.unregisterReceiver(pairReceiver); + if (discoveryCallback != null) { + ThreadHelper.run(runOnUi, activity, new Runnable() { + @Override + public void run() { + discoveryCallback.onPairingFailed(device); + } + }); + } } } else if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)){ diff --git a/bluetooth/src/main/java/me/aflak/bluetooth/interfaces/DiscoveryCallback.java b/bluetooth/src/main/java/me/aflak/bluetooth/interfaces/DiscoveryCallback.java index 7a67a44..e274200 100644 --- a/bluetooth/src/main/java/me/aflak/bluetooth/interfaces/DiscoveryCallback.java +++ b/bluetooth/src/main/java/me/aflak/bluetooth/interfaces/DiscoveryCallback.java @@ -13,4 +13,5 @@ public interface DiscoveryCallback{ void onDevicePaired(BluetoothDevice device); void onDeviceUnpaired(BluetoothDevice device); void onError(int errorCode); + void onPairingFailed(BluetoothDevice device); } \ No newline at end of file