我需要通过蓝牙传递Intent。我当然创造了这个游戏,并且我在一个类型单身人士中保存了游戏的特性。
我想要做的是将这些信息传递给我已经连接的其他设备,并开始以前我或他/她创建的游戏。
如何发送此信息和游戏活动?
我使用andengine制作所有游戏。
谢谢!
答案 0 :(得分:0)
我认为this site可能会对您有所帮助。有几种方法,但你想要OP中提到的最后一种方法。
public void sendFile(Uri uri, BluetoothSocket bs) throws IOException {
BufferedInputStream bis = new BufferedInputStream(getContentResolver().openInputStream(uri));
OutputStream os = bs.getOutputStream();
try {
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
// we need to know how may bytes were read to write them to the byteBuffer
int len = 0;
while ((len = bis.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
} finally {
bis.close();
os.flush();
os.close();
bs.close();
}
}
希望这有帮助。