Udostępnij za pośrednictwem


CompanionDeviceManager.StartObservingDevicePresence(String) Method

Definition

Register to receive callbacks whenever the associated device comes in and out of range.

[Android.Runtime.Register("startObservingDevicePresence", "(Ljava/lang/String;)V", "", ApiSince=31)]
[Android.Runtime.RequiresPermission("android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE")]
public void StartObservingDevicePresence (string deviceAddress);
[<Android.Runtime.Register("startObservingDevicePresence", "(Ljava/lang/String;)V", "", ApiSince=31)>]
[<Android.Runtime.RequiresPermission("android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE")>]
member this.StartObservingDevicePresence : string -> unit

Parameters

deviceAddress
String

a previously-associated companion device's address

Attributes

Remarks

Register to receive callbacks whenever the associated device comes in and out of range.

The provided device must be #associate associated with the calling app before calling this method.

Caller must implement a single CompanionDeviceService which will be bound to and receive callbacks to CompanionDeviceService#onDeviceAppeared and CompanionDeviceService#onDeviceDisappeared. The app doesn't need to remain running in order to receive its callbacks.

Calling app must declare uses-permission android.Manifest.permission#REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE.

Calling app must check for feature presence of PackageManager#FEATURE_COMPANION_DEVICE_SETUP before calling this API.

For Bluetooth LE devices, this is based on scanning for device with the given address. The system will scan for the device when Bluetooth is ON or Bluetooth scanning is ON.

For Bluetooth classic devices this is triggered when the device connects/disconnects. WiFi devices are not supported.

If a Bluetooth LE device wants to use a rotating mac address, it is recommended to use Resolvable Private Address, and ensure the device is bonded to the phone so that android OS is able to resolve the address.

Java documentation for android.companion.CompanionDeviceManager.startObservingDevicePresence(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to