简体   繁体   English

android蓝牙文件传输失败

[英]android bluetooth file transfer failure

here i am trying to send a file over bluetooth but its not sending any data. 在这里,我正在尝试通过蓝牙发送文件,但未发送任何数据。 here the main problem is that its not sending or receiving any data over the two devices but they are connected to each other. 这里的主要问题是它没有通过两个设备发送或接收任何数据,但是它们彼此连接。

Sending code: 发送代码:

File myFile = new File(message.toURI());
Double nosofpackets = Math.ceil(((int) myFile.length() )/4096);
System.out.println(nosofpackets);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile));
byte[] send = new byte[4096];
for(double i = 0; i < nosofpackets; i++)
{
    send = null ;
    a=bis.read(send, 0, send.length);
    Log.d("BluetoothChat", "data packet " + i);
    if(a == -1)
    {
        break;
    }
    mChatService.write(send);
}

Receiving code : 接收代码:

while((bytes = mmInStream.read(buffer)) > 0)
{
    Log.d(TAG, "data is there for writing");
    bos.write(buffer);
}

您可能想检出此库,以便使用蓝牙在Android设备之间发送文件和其他数据(免责声明:我是作者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM