Android 如何使用安卓&x27;s Wi-Fi直接发送和接收阵列列表<;字符串>;从一部手机上的应用程序到另一部手机上的应用程序的对象?

Android 如何使用安卓&x27;s Wi-Fi直接发送和接收阵列列表<;字符串>;从一部手机上的应用程序到另一部手机上的应用程序的对象?,android,p2p,wifi-direct,Android,P2p,Wifi Direct,我已经看过Android wifi p2p API,并看过了“WiFiDirectActivity”中提供的示例代码,它允许手机将图像文件从一部手机传输到另一部手机。他们使用的代码是: // Allow user to pick an image from Gallery or other // registered apps Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); sta

我已经看过Android wifi p2p API,并看过了“WiFiDirectActivity”中提供的示例代码,它允许手机将图像文件从一部手机传输到另一部手机。他们使用的代码是:

// Allow user to pick an image from Gallery or other
// registered apps
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);

问题是这只是一种方法,它只传输文件,而我想将其实现到我的pvp卡游戏应用程序代码中,以传输ArrayList对象。我该怎么做?我不想传输txt文件,我的代码中有一个文件缓冲区。我还没有找到任何好的教程来展示如何将wifi直接连接整合到更大的应用程序中。

我对这个主题也有点陌生(Android,尤其是Wi-Fi直接p2p),但我认为它可以传输字节。因此,如果将ArrayList转换为字节数组,如下所示:

byte[] result = new byte[list.size()];
for(int i=0; i<list.size; i++){ 
    result[i] = list.get(i).byteValue();
}
byte[]result=新字节[list.size()];
对于(int i=0;i