/** * Configures the {@link mobisocial.nfc.Nfc} interface to set up a Bluetooth socket with another * device. The method both sets the foreground ndef messages and registers an {@link * mobisocial.nfc.NdefHandler} to look for incoming pairing requests. * * <p>When this method is called, a Bluetooth server socket is created, and the socket is closed * after a successful connection. You must call prepare() again to reinitiate the server socket. * * @return The server socket listening for peers. */ public static BluetoothServerSocket prepare( Nfc nfc, OnConnectedListener conn, NdefRecord[] ndef) { BluetoothConnecting btConnecting = new BluetoothConnecting(conn); NdefMessage handoverRequest = btConnecting.getHandoverRequestMessage(nfc.getContext()); NdefRecord[] combinedRecords = new NdefRecord[ndef.length + handoverRequest.getRecords().length]; int i = 0; for (NdefRecord r : ndef) { combinedRecords[i++] = r; } for (NdefRecord r : handoverRequest.getRecords()) { combinedRecords[i++] = r; } NdefMessage outbound = new NdefMessage(combinedRecords); nfc.getConnectionHandoverManager().addConnectionHandover(btConnecting); nfc.share(outbound); return btConnecting.mAcceptThread.mmServerSocket; }
/** * Configures the {@link mobisocial.nfc.Nfc} interface to set up a Bluetooth socket with another * device. The method both sets the foreground ndef messages and registers an {@link * mobisocial.nfc.NdefHandler} to look for incoming pairing requests. * * <p>When this method is called, a Bluetooth server socket is created, and the socket is closed * after a successful connection. You must call prepare() again to reinitiate the server socket. * * @return The server socket listening for peers. */ public static BluetoothServerSocket prepare(Nfc nfc, OnConnectedListener conn) { BluetoothConnecting btConnecting = new BluetoothConnecting(conn); nfc.getConnectionHandoverManager().addConnectionHandover(btConnecting); nfc.share(btConnecting.getHandoverRequestMessage(nfc.getContext())); return btConnecting.mAcceptThread.mmServerSocket; }