标签: bluetooth-socket

通过蓝牙发送/接收数据

我正在尝试从Android设备发送/接收字符串.我一直在谷歌搜索过去3个小时,我找不到任何有效的东西.我得到的最接近的是:家伙

我收到这些错误:

02-19 15:44:17.680    4680-4680/com.example.jelle.bluetoothconnector W/System.err? at com.example.jelle.bluetoothconnector.BluetoothConnection.init(BluetoothConnection.java:38)
02-19 15:44:17.680    4680-4680/com.example.jelle.bluetoothconnector W/System.err? at com.example.jelle.bluetoothconnector.BluetoothConnection.<init>(BluetoothConnection.java:25)
02-19 15:44:17.680    4680-4680/com.example.jelle.bluetoothconnector W/System.err? at com.example.jelle.bluetoothconnector.ConnectorActivity.btnBluetooth_onCLick(ConnectorActivity.java:92)
02-19 15:44:17.680    4680-4680/com.example.jelle.bluetoothconnector W/System.err? at java.lang.reflect.Method.invoke(Native Method)
02-19 15:44:17.680    4680-4680/com.example.jelle.bluetoothconnector W/System.err? at java.lang.reflect.Method.invoke(Method.java:372)
Run Code Online (Sandbox Code Playgroud)

谁能帮我?我只需要一些可以通过蓝牙发送/接收字符串的代码来启动我

谢谢!

sockets android bluetooth android-bluetooth bluetooth-socket

7
推荐指数
1
解决办法
1万
查看次数

java.io.IOException:读取失败,socket可能关闭或超时,在Android 5.0.1 Lollipop版本上读取ret:-1

我正在与蓝牙设备进行蓝牙套接字连接,并希望从设备读取字节.

我已正确建立连接:

 try {
         Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
          temp = (BluetoothSocket) m.invoke(mmDevice, 1);
 } catch (Exception e) {
 }
Run Code Online (Sandbox Code Playgroud)

我正在从蓝牙设备正确读取字节.

我得到了例外:

java.io.IOException:读取失败,socket可能关闭或超时,读取ret:-1

因此,连接断开,我的设备和蓝牙设备之间的通信也结束了.

这个问题特别在Android 5.0.1 Lollipop上出现

任何人都有解决方法吗?

android bluetooth bluetooth-socket android-5.0-lollipop

6
推荐指数
1
解决办法
1万
查看次数

Android蓝牙套接字没有给出预期的确认

我正在向蓝牙插座发送一个字节数组,我从蓝牙打印机得到响应,但我没有得到正确的图像数据发送确认.

outputstream按以下方式编写字节数组:

byte[] queryData = new byte[]{
    0x1B, 0x2A, 0x43, 0x41,
    0x00, 0x00, 0x00, 0x00,
    0x01, 0x27, 0x5E,
    0x01, 0x00, 0x00, 0x00, 0x00
};
outputStream.write(queryData);
outputStream.flush();
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以写二进制数据outputstream吗?

我被卡住并打开了任何建议.

android bluetooth outputstream bluetooth-profile bluetooth-socket

5
推荐指数
0
解决办法
368
查看次数

Android BluetoothSocket连接返回零

我们的设备通过蓝牙发送数据,在Android应用程序中我们需要读取这些数据.

我能够建立蓝牙连接,接下来我正在调用一个Thread来使用BluetoothDevice建立BluetoothSocket连接.在读取字节时,它返回0(零)此外,while循环仅运行一次.

我在下面的代码中使用的UUID也来自某些蓝牙代码段.我是否需要获取设备的正确UUID.

请有人帮忙吗?.如果你给我一个有用的答案,我将非常感谢.

   //Calling ConnectThread after Bluetooth is paired
    public class ConnectThread extends Thread {
            private final BluetoothSocket mmSocket;
            private final BluetoothDevice mmDevice;
            private final UUID MY_UUID = UUID
                    .fromString("00001101-0000-1000-8000-00805f9b34fb");

            public ConnectThread(BluetoothDevice device) {
                BluetoothSocket tmp = null;
                mmDevice = device;
                try {
                    String name = device.getName();
                    Log.e("Device Name ", name);
                    tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
                } catch (IOException e) {
                }
                mmSocket = tmp;
            }

            public void run() {
                // mAdapter.cancelDiscovery();
                try {
                    mmSocket.connect();

                    ConnectedThread mConnectedThread = new ConnectedThread(mmSocket);
                    mConnectedThread.start(); …
Run Code Online (Sandbox Code Playgroud)

android android-bluetooth bluetooth-socket

5
推荐指数
1
解决办法
811
查看次数