Freigeben über


BluetoothAdapter.StartDiscovery Method

Definition

Start the remote device discovery process.

[Android.Runtime.Register("startDiscovery", "()Z", "")]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_SCAN")]
public bool StartDiscovery ();
[<Android.Runtime.Register("startDiscovery", "()Z", "")>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_SCAN")>]
member this.StartDiscovery : unit -> bool

Returns

true on success, false on error

Attributes

Remarks

Start the remote device discovery process.

The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

This is an asynchronous call, it will return immediately. Register for #ACTION_DISCOVERY_STARTED and #ACTION_DISCOVERY_FINISHED intents to determine exactly when the discovery starts and completes. Register for BluetoothDevice#ACTION_FOUND to be notified as remote Bluetooth devices are found.

Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use #cancelDiscovery() to cancel an ongoing discovery. Discovery is not managed by the Activity, but is run as a system service, so an application should always call BluetoothAdapter#cancelDiscovery() even if it did not directly request a discovery, just to be sure.

Device discovery will only find remote devices that are currently discoverable (inquiry scan enabled). Many Bluetooth devices are not discoverable by default, and need to be entered into a special mode.

If Bluetooth state is not #STATE_ON, this API will return false. After turning on Bluetooth, wait for #ACTION_STATE_CHANGED with #STATE_ON to get the updated value.

If a device is currently bonding, this request will be queued and executed once that device has finished bonding. If a request is already queued, this request will be ignored.

Java documentation for android.bluetooth.BluetoothAdapter.startDiscovery().

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