Advertisement
ajelly

BluetoothConnection.java - open()

Feb 16th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1.   public boolean open (int inputPipe, int channel, boolean secure) {
  2.  
  3.     Log.d(LOG_TAG, "AJ: Inside open, channel:"+channel+", secure:"+secure);
  4.     if (channel == 0) {
  5.       try {
  6.         bluetoothSocket = secure? bluetoothDevice.createRfcommSocketToServiceRecord(SERIAL_PROFILE_UUID):
  7.                                   bluetoothDevice.createInsecureRfcommSocketToServiceRecord(SERIAL_PROFILE_UUID);
  8.       } catch (IOException exception) {
  9.         Log.e(LOG_TAG, "Bluetooth UUID resolution failed: " + bluetoothAddress + ": " + exception.getMessage());
  10.         bluetoothSocket = null;
  11.       }
  12.     } else {
  13.       Log.d(LOG_TAG, "AJ: createRfcommSocket");
  14.       bluetoothSocket = createRfcommSocket(bluetoothDevice, channel);
  15.     }
  16.  
  17.     if (bluetoothSocket != null) {
  18.       try {
  19.         Log.d(LOG_TAG, "AJ: before connect()");
  20.         bluetoothSocket.connect();
  21.  
  22.         inputStream = bluetoothSocket.getInputStream();
  23.         outputStream = bluetoothSocket.getOutputStream();
  24.  
  25.         Log.d(LOG_TAG, "AJ: before pipe creation");
  26.  
  27.         {
  28.           File pipeFile = new File("/proc/self/fd/" + inputPipe);
  29.           pipeStream = new FileOutputStream(pipeFile);
  30.         }
  31.  
  32.         Log.d(LOG_TAG, "AJ: before inputThread.start()");
  33.         inputThread = new InputThread();
  34.         inputThread.start();
  35.         Log.d(LOG_TAG, "AJ: Ok, return");
  36.         return true;
  37.       } catch (IOException openException) {
  38.         Log.e(LOG_TAG, "Bluetooth connect failed: " + bluetoothAddress + ": " + openException.getMessage());
  39.       }
  40.     }
  41.  
  42.     close();
  43.     return false;
  44.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement