Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新Android 4.2.2后,蓝牙流停止。至4.4.2_Android_Bluetooth - Fatal编程技术网

更新Android 4.2.2后,蓝牙流停止。至4.4.2

更新Android 4.2.2后,蓝牙流停止。至4.4.2,android,bluetooth,Android,Bluetooth,我正在开发Android应用程序,它不断地从医疗设备接收数据。配置为串行Com端口的设备 在安卓4.2.2上,一切正常。在将华硕K00E更新为安卓4.4.2之后,出现了一个问题 连接后,设备立即开始传输数据。 Asus正常接收数据几秒钟后停止。 日志中没有错误 视频在此: 注意最后几秒钟 连接片段: protected Void ConnectToCardioBT(BluetoothDevice device) { try { Method m = null;

我正在开发Android应用程序,它不断地从医疗设备接收数据。配置为串行Com端口的设备

在安卓4.2.2上,一切正常。在将华硕K00E更新为安卓4.4.2之后,出现了一个问题

连接后,设备立即开始传输数据。 Asus正常接收数据几秒钟后停止。 日志中没有错误

视频在此:

注意最后几秒钟

连接片段:

    protected Void ConnectToCardioBT(BluetoothDevice device) {
    try {
        Method m = null;
        try {
            m = device.getClass().getMethod("createRfcommSocket",
                    new Class[] { int.class });
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        try {
            socket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        socket.connect();
    private class ConnectedThread extends Thread {
    private final InputStream mmInStream;

    public ConnectedThread(BluetoothSocket socket) {
        InputStream tmpIn = null;
        try {
            tmpIn = socket.getInputStream();
        } catch (IOException e) {
        }
        mmInStream = tmpIn;
    }

    public void run() {

        byte[] buffer = new byte[2048];
        int bytes; 

        while (true) {
            try {

                Log.d(TAG,Integer.toString(mmInStream.available())+": " + new Date().getTime());
                bytes = mmInStream.read(buffer);

从流片段读取:

    protected Void ConnectToCardioBT(BluetoothDevice device) {
    try {
        Method m = null;
        try {
            m = device.getClass().getMethod("createRfcommSocket",
                    new Class[] { int.class });
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        try {
            socket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        socket.connect();
    private class ConnectedThread extends Thread {
    private final InputStream mmInStream;

    public ConnectedThread(BluetoothSocket socket) {
        InputStream tmpIn = null;
        try {
            tmpIn = socket.getInputStream();
        } catch (IOException e) {
        }
        mmInStream = tmpIn;
    }

    public void run() {

        byte[] buffer = new byte[2048];
        int bytes; 

        while (true) {
            try {

                Log.d(TAG,Integer.toString(mmInStream.available())+": " + new Date().getTime());
                bytes = mmInStream.read(buffer);


非常感谢您的帮助。

解决方案如下:

由于一些未知的原因,需要定期向发送设备发送一些命令。在这种情况下,传输不会停止。如果有人知道原因,请发表评论。谢谢