2

我需要通过蓝牙传递一个意图。以前我创建了游戏,并将游戏的特征保存在一个类类型的单例中。

我想要做的是将此信息传递给我已经连接的其他设备并开始我或他/她之前创建的游戏。

如何发送此信息和游戏活动?

我使用andengine来制作所有的游戏。

谢谢!

4

1 回答 1

0

我认为这个网站可以帮助你。有几种方法,但您需要 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();
    }
}

希望这可以帮助。

于 2013-08-09T12:34:12.217 回答