在这里,我试图通过蓝牙发送文件,但它不发送任何数据。这里的主要问题是它没有通过两个设备发送或接收任何数据,但它们相互连接。
发送代码:
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);
}
接收代码:
while((bytes = mmInStream.read(buffer)) > 0)
{
Log.d(TAG, "data is there for writing");
bos.write(buffer);
}