2
這裏我想通過藍牙發送文件,但它不發送任何數據。 這裏主要的問題是它不通過這兩個設備發送或接收任何數據,但它們彼此連接。安卓藍牙文件傳輸失敗
發送代碼:
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);
}
你可以參考http://tsicilian.wordpress.com/2012/11/ 06/bluetooth-data-transfer-with-android/ – Anu 2013-03-14 04:19:42
@Anu是可以發送多個用戶在一次使用該代碼的意圖設置..我的意思是說,假設我試圖發送相同的文件到4或更多的配對設備在一次去..這是可能的..? – 2013-03-16 10:09:10