相关疑难解决方法(0)

蓝牙文件传输Android

我在通过蓝牙套接字发送大文件时遇到问题.较小的文件正确传输.我相信最多可以正确传输161280个字节.

编辑:我做了一些测试并缩小了原因.看起来

outStream.write(mybytearray, 0, mybytearray.length);
Run Code Online (Sandbox Code Playgroud)

在发送代码部分不写超过161280字节.我通过不关闭套接字连接看到了这种行为,从而导致read接收部分在161280字节上"阻塞".这里的蓝牙输出流有什么问题?我究竟做错了什么?

编辑2: 这样做让它通过.

for(int i = 0 ; i < mybytearray.length ; i++){
    outStream.write(mybytearray[i]);
}
Run Code Online (Sandbox Code Playgroud)

发送代码:

    try {
        outStream = mBluetoothSocket.getOutputStream();
        Log.d(TAG,"outStream created success!");
    } catch (IOException e) {
        Log.d(TAG,
                "ON RESUME: Output stream creation failed.",
                e);
    }

    File myFile = new File(file_name);
    Log.d(TAG,"file /source.pdf created success!");

    byte[] mybytearray = new byte[(int)myFile.length()];
    Log.d(TAG,"file length() =" + (int)myFile.length());

    FileInputStream fis = new FileInputStream(myFile);
    Log.d(TAG,"fis created");

    BufferedInputStream bis = new BufferedInputStream(fis,1272254 );
    Log.d(TAG,"bis created …
Run Code Online (Sandbox Code Playgroud)

android bluetooth file-transfer

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

标签 统计

android ×1

bluetooth ×1

file-transfer ×1