Advertisement
Guest User

Untitled

a guest
Jul 26th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. private void sendDataToPairedDevice(String message, String adress) {
  2. byte[] toSend = message.getBytes();
  3. try {
  4. BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(adress);
  5. // BluetoothSocket socket
  6. // =device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"));
  7. BluetoothSocket socket = null;
  8. Method m = null;
  9. try {
  10. m = device.getClass().getMethod("createRfcommSocket",
  11. new Class[] { int.class });
  12. } catch (Exception e) {
  13. e.printStackTrace();
  14. }
  15. try {
  16. socket = (BluetoothSocket) m.invoke(device, 1);
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20.  
  21. OutputStream mmOutStream = socket.getOutputStream();
  22. mBluetoothAdapter.cancelDiscovery();
  23. socket.connect();
  24. mmOutStream.write(toSend);
  25. } catch (Exception e) {
  26. Log.d("TAG", "Exception during write", e);
  27. }
  28. }
  29.  
  30. case MESSAGE_READ:
  31. byte[] readBuf = (byte[]) msg.obj;
  32. // construct a string from the valid bytes in the buffer
  33. String readMessage = new String(readBuf, 0, msg.arg1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement