几天后,我在他们的API中分析了android的蓝牙聊天示例。我正在尝试修改示例,以便我可以发送序列化对象。但是,到目前为止我没有运气。我已经尝试了一切。我只是想通过蓝牙发送对象。非常感谢任何帮助或指导。
byte[] readBuf = (byte[]) msg.obj;
Object o = toObject(readBuf);
System.out.println("MESSAGE_READ: " +readMessage);//this is being called multiple
//times from a thread. hence, the object is being constructed only partially. how
//do i resolve this?
public Object toObject (byte[] bytes)
{
Object obj = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream (bytes);
ObjectInputStream ois = new ObjectInputStream (bis);
obj = ois.readObject();
}
catch (IOException ex) {
//TODO: Handle the exception
}
catch (ClassNotFoundException ex) {
//TODO: Handle the exception
}
return obj;
}