Sending bluetooth strings in android

Ok, so I have a bluetooth.java class that (I was hoping) would send its own strings. However, whenever I try to send a command, my broken toasts just show that not. Is something vital enough missing? I have only these 2 functions.

void openBT() throws IOException { UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); try { mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Unable to create socket", Toast.LENGTH_LONG).show(); } try { mmSocket.connect(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "Unable to connect to socket", Toast.LENGTH_LONG).show(); } mmOutputStream = mmSocket.getOutputStream(); mmInputStream = mmSocket.getInputStream(); } void sendData2() throws IOException { if (BtCommand == "0"){ msg = "Fan2 Off"; } if (BtCommand == "1"){ msg = "Fan2 On"; } mmOutputStream.write(msg.getBytes()); } 

and these are the only things that I installed

  BluetoothSocket mmSocket; BluetoothDevice mmDevice; String BtCommand; OutputStream mmOutputStream; InputStream mmInputStream 

I am sure this is an openBT function that fails, I am connected to the device in order.

+5
source share
1 answer

Are you sure with the selected UUID?

UUID List

Also, try recycling the code. I use 2 streams (1 for connection and second connection and connection)

0
source

Source: https://habr.com/ru/post/1241123/


All Articles