import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
/**
* Represents a remote Bluetooth device. A {@link BluetoothDevice} lets you
* intents to indicate pairing method used. Possible values are:
* {@link #PAIRING_VARIANT_PIN},
* {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION},
+ * {@link #PAIRING_VARIANT_PASSKEY},
*/
public static final String EXTRA_PAIRING_VARIANT =
"android.bluetooth.device.extra.PAIRING_VARIANT";
/**
* The user will be prompted to enter a passkey
- * @hide
*/
public static final int PAIRING_VARIANT_PASSKEY = 1;
return false;
}
- /** @hide */
+ /**
+ * Set the passkey during pairing when the pairing method is
+ * {@link #PAIRING_VARIANT_PASSKEY}
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
+ *
+ * @return true if passkey has been set
+ * flase for error
+ */
public boolean setPasskey(int passkey) {
- //TODO(BT)
- /*
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot set Remote Device passkey");
+ return false;
+ }
+ ByteBuffer buff = ByteBuffer.allocate(5);
+ buff.order(ByteOrder.nativeOrder());
+ buff.putInt(passkey);
+ byte[] passkeyByte = buff.array();
+
try {
- return sService.setPasskey(this, true, 4, passkey);
- } catch (RemoteException e) {Log.e(TAG, "", e);}*/
+ return sService.setPasskey(this, true, passkeyByte.length, passkeyByte);
+ } catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}