0
真的需要一些帮助。 对于已经有一周的时间,我试着将(原始)数据(-bytes)正确保存到我的Android手机的SD卡中。SD卡 - >缺失值
移动从微控制器获得通过蓝牙数据。数据由终端正确输出,所以显然Java代码不正确。
为了测试这一点,一个变量(8位)的递增和该步骤之后的变量的值被发送到手机上。 当我读出用内六角视图创建的文件,也有很多有罪值之间的零(时:μC不发送任何东西),由于某种原因有缺失/甚至年表很多价值观是错的。
节约部分:
h=new Handler() {
public void handleMessage (android.os.Message msg) {
switch (msg.what) {
case RECIEVE_MESSAGE:
byte[] readBuf = (byte[]) msg.obj;
String path = "/sdcard/" + dateipfad.getText().toString() + ".txt";
Environment.getExternalStorageDirectory().getPath();
try {
File myFile = new File(path);
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile,true);
fOut.write(readBuf);
fOut.flush();
fOut.close();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
break;
}
}
};
`
感谢您的回复。 你确定,这是问题吗? 我的意思是这是不够的,创建一个这样的文件流: byte [] readBuf =(byte [])msg.obj; fOut.write(readBuf); fOut.flush(); fOut.close(); 如果没有,你能请解释原因,以及如何做到这一点是正确的,我PROGRAMM与Android工作室,我'这个IDE和JAVA很新。以及如何将你的代码行粘贴到我的? - > keyOfMessage? – bandschuka
什么是发送消息到您的处理程序? – confusedProgrammer
μc通过蓝牙(等级:2.0)。 BLE:HC06(Uart)。 也许这就是同样的问题: https://stackoverflow.com/questions/35157297/android-bluetooth-adapter-message-handler-buffer-limit ? – bandschuka