Skip to content
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
24 changes: 18 additions & 6 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ public BleManager(@NonNull final Context context, @NonNull final Handler handler
this.requestHandler = getGattCallback();
this.requestHandler.init(this, handler);

ContextCompat.registerReceiver(context, mPairingRequestBroadcastReceiver,
// BluetoothDevice.ACTION_PAIRING_REQUEST
new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST"),
ContextCompat.RECEIVER_EXPORTED);
if (isPairingSupported()) {
ContextCompat.registerReceiver(context, mPairingRequestBroadcastReceiver,
// BluetoothDevice.ACTION_PAIRING_REQUEST
new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST"),
ContextCompat.RECEIVER_EXPORTED);
}
}

/**
Expand Down Expand Up @@ -251,6 +253,16 @@ protected boolean isOptionalServiceSupported(@NonNull final BluetoothGatt gatt)
return requestHandler.isOptionalServiceSupported(gatt);
}

/**
* This method should return <code>true</code> if your want to be able to pair with
* the gatt device. If you return false, the pairing request BroadcastReceiver will
* not be registered.
*/
protected boolean isPairingSupported() {
// Don't call super.isPairingSupported() when overriding this method.
return true;
}

/**
* In this method the manager should get references to server characteristics and descriptors
* that will use. The method is called after the service discovery of a remote device has
Expand Down Expand Up @@ -301,9 +313,9 @@ protected void onManagerReady() {
* Closes and releases resources. When the device disconnected with link loss and
* {@link ConnectRequest#shouldAutoConnect()} returned true you have to call this method to
* close the connection. If you intend to reuse this instance for multiple connections,
* do not call this method after {@link #disconnect()}. If you are done with this instance,
* do not call this method after {@link #disconnect()}. If you are done with this instance,
* call this method from the {@link #disconnect()} completion handler, e.g.
* <code>disconnect().then { close() }</code>.
* <code>disconnect().then { close() }</code>.
*/
public void close() {
try {
Expand Down