Interface PolarCompanionDeviceApi
-
- All Implemented Interfaces:
public interface PolarCompanionDeviceApiAPI for integrating Android's Companion Device Manager (CDM) with a Polar device connection.
Once a device is associated through this API, the app can request relaxed background execution privileges and receive device presence notifications (device entering/leaving BLE range) via a declared
CompanionDeviceService, without needing a continuous BLE scan.This API complements, and does not replace, PolarBleApi.searchForDevice / PolarBleApi.connectToDevice. Typical flow:
Call createAssociationRequest and associate to have the user pick/approve a Polar device.
On success, call startObservingDevicePresence with the returned MAC address.
When PolarCompanionDeviceCallback.onDeviceAppeared fires, call PolarBleApi.connectToDevice.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePolarCompanionDeviceApi.PolarCompanionDeviceCallbackCallback describing device presence / association events surfaced through the wrapped Companion Device Manager APIs.
-
Method Summary
Modifier and Type Method Description abstract BooleanisCompanionDeviceManagerAvailable()abstract AssociationRequestcreateAssociationRequest(String namePrefix, Boolean singleDevice)Builds an association request that will match nearby Polar devices. abstract Unitassociate(AssociationRequest request, Function1<IntentSender, Unit> onIntentSender, PolarCompanionDeviceApi.PolarCompanionDeviceCallback callback)Starts the association flow for request. abstract UnitlaunchAssociation(Activity activity, IntentSender intentSender, Integer requestCode)Convenience helper to launch an association IntentSender using the legacy startIntentSenderForResultActivity API.abstract List<String>getAssociatedDeviceAddresses()abstract BooleanisAssociated(String identifier)abstract UnitremoveAssociation(String identifier)Removes the CDM association for the device behind identifier. abstract BooleanstartObservingDevicePresence(String identifier, PolarCompanionDeviceApi.PolarCompanionDeviceCallback callback)Starts observing device presence for the device behind identifier (must already be associated). abstract BooleanstopObservingDevicePresence(String identifier)Stops observing device presence previously started with startObservingDevicePresence. abstract BooleanrequestBackgroundExecutionPrivilege(Activity activity, Integer requestCode)Requests the "run in background" companion privilege (API 33+), which relaxes background execution / BLE scan throttling limits for companion apps. -
-
Method Detail
-
isCompanionDeviceManagerAvailable
abstract Boolean isCompanionDeviceManagerAvailable()
- Returns:
true if the Companion Device Manager feature is available on this OS version/device.
-
createAssociationRequest
abstract AssociationRequest createAssociationRequest(String namePrefix, Boolean singleDevice)
Builds an association request that will match nearby Polar devices.
- Parameters:
namePrefix- required BLE advertised name prefix, default "Polar"singleDevice- restrict user selection to a single device
-
associate
abstract Unit associate(AssociationRequest request, Function1<IntentSender, Unit> onIntentSender, PolarCompanionDeviceApi.PolarCompanionDeviceCallback callback)
Starts the association flow for request. If user confirmation is required, the resulting IntentSender is delivered through onIntentSender and the caller (Activity) must launch it, e.g. with
ActivityResultContracts.StartIntentSenderForResult.- Parameters:
onIntentSender- invoked with the IntentSender to launch for user consentcallback- invoked with the outcome of the association
-
launchAssociation
abstract Unit launchAssociation(Activity activity, IntentSender intentSender, Integer requestCode)
Convenience helper to launch an association IntentSender using the legacy
startIntentSenderForResultActivity API.
-
getAssociatedDeviceAddresses
abstract List<String> getAssociatedDeviceAddresses()
- Returns:
BT MAC addresses of devices already CDM-associated with this app.
-
isAssociated
abstract Boolean isAssociated(String identifier)
- Returns:
true if the device behind identifier (Polar device id or BT address) is currently CDM-associated.
-
removeAssociation
abstract Unit removeAssociation(String identifier)
Removes the CDM association for the device behind identifier.
-
startObservingDevicePresence
abstract Boolean startObservingDevicePresence(String identifier, PolarCompanionDeviceApi.PolarCompanionDeviceCallback callback)
Starts observing device presence for the device behind identifier (must already be associated). Presence changes are reported via callback.
- Returns:
true if observation was started successfully
-
stopObservingDevicePresence
abstract Boolean stopObservingDevicePresence(String identifier)
Stops observing device presence previously started with startObservingDevicePresence.
-
requestBackgroundExecutionPrivilege
abstract Boolean requestBackgroundExecutionPrivilege(Activity activity, Integer requestCode)
Requests the "run in background" companion privilege (API 33+), which relaxes background execution / BLE scan throttling limits for companion apps. Must be called from an Activity; result is delivered to that activity's
onActivityResult.- Returns:
true if the request was launched
-
-
-
-