[問題] 藍芽傳值
最近使用藍芽的時候,想用藍芽傳大筆資料出去
使用STREAM的方式,一次大約1k Byte左右
(檔案最小大約25K,大的話差不多3Mb左右)
為何傳完都要DELAY一小段時間,對方才能收到
才能繼續往下傳
如何讓傳遞速度增加?手機用藍芽傳輸的速度還蠻快的
想試試看可以可以跟手機都速度差不多
接收端我用ARDUINO+HC06模組
String path = Environment.getExternalStorageDirectory().getPath();
File file = new File(path + "/" + "data.txt");
int i = 0;
try {
fin = new FileInputStream(file);
ByteArrayOutputStream byteBuffer = new
ByteArrayOutputStream();
//byte[] wrong=new byte[2048];
byte[] data = new byte[1000];
//byte[] test=new byte[100];
int length = 0;
while ((length = fin.read(data)) != -1) {
byteBuffer.write(data, 0, length);
mmOutStream.write(data);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mmOutStream.flush();
android.util.Log.i("DATA MESSAGE", "" + data +
"------------" + i);
i++;
}
fin.close();
android.util.Log.i("TAG OVER", "OK OK OK OK OK OK OK
OK OK");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
startSend = false;
android.util.Log.i("TAG OVER", "" + count);String path = E
nv
File file = new File(path + "/" + "data.txt");
int i = 0;
try {
fin = new FileInputStream(file);
ByteArrayOutputStream byteBuffer = new
ByteArrayOutputStream();
//byte[] wrong=new byte[2048];
byte[] data = new byte[1000];
//byte[] test=new byte[100];
int length = 0;
while ((length = fin.read(data)) != -1) {
byteBuffer.write(data, 0, length);
mmOutStream.write(data);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mmOutStream.flush();
android.util.Log.i("DATA MESSAGE", "" + data +
"------------" + i);
i++;
}
fin.close();
android.util.Log.i("TAG OVER", "OK OK OK OK OK OK OK
OK OK");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
startSend = false;
android.util.Log.i("TAG OVER", "" + count);
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.150.234
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1447679821.A.59F.html
→
11/16 21:28, , 1F
11/16 21:28, 1F
※ 編輯: barry0123 (223.140.23.96), 11/16/2015 21:59:18
→
11/20 08:16, , 2F
11/20 08:16, 2F
→
11/20 08:30, , 3F
11/20 08:30, 3F
→
11/20 08:31, , 4F
11/20 08:31, 4F