/** * Cancel the current device discovery process. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. * * <p>Because discovery is a heavyweight procedure for the Bluetooth adapter, this method should * always be called before attempting to connect to a remote device with {@link * android.bluetooth.BluetoothSocket#connect()}. Discovery is not managed by the Activity, but is * run as a system service, so an application should always call cancel discovery even if it did * not directly request a discovery, just to be sure. * * <p>If Bluetooth state is not {@link #STATE_ON}, this API will return false. After turning on * Bluetooth, wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON} to get the updated * value. * * @return true on success, false on error */ public boolean cancelDiscovery() { if (getState() != STATE_ON) return false; try { mService.cancelDiscovery(); } catch (RemoteException e) { Log.e(TAG, "", e); } return false; }