Advertisement
Guest User

Untitled

a guest
May 24th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public void connect(View v){
  2. BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  3. BluetoothDevice device = adapter.getRemoteDevice(ADDR);
  4. try {
  5. BluetoothSocket bs = device.createRfcommSocketToServiceRecord(_UUID);
  6. Field f = bs.getClass().getDeclaredField("mFdHandle");
  7. f.setAccessible(true);
  8. f.set(bs, 0x8000);
  9. bs.close();
  10. Thread.sleep(2000); // Just in case the socket was really connected
  11. } catch (Exception e) {
  12. Log.e(TAG, "Reset Failed", e);
  13. }
  14. try {
  15. this._socket = device.createRfcommSocketToServiceRecord(_UUID);
  16. this._socket.connect();
  17. } catch (IOException e) {
  18. Log.e(TAG, "create() failed", e);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement