简体   繁体   English

WifiDirectActivity示例更改:传输ArrayList <String> P2P

[英]WifiDirectActivity Sample alteration: Transfer an ArrayList<String> p2p

I have looked at the Android wifi p2p API here and have taken a look at the sample code provided in "WiFiDirectActivity" which simply allows phones to transfer image files from one phone to another. 我在这里查看了Android wifi p2p API并查看了“WiFiDirectActivity”中提供的示例代码,该代码只允许手机将图像文件从一部手机传输到另一部手机。 The code they use for this is: 他们用于此的代码是:

public void onClick(View v) 
{
    // 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);
}

I have changed it to the following with no Compiler errors: 我已将其更改为以下内容而没有编译器错误:

public void onClick(View v) 
{
    // Allow user to pick an image from Gallery or other
    // registered apps
    ArrayList<String> deck = new ArrayList<String>();
    deck.add("Lulz");
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("ArrayList<String>");
    startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
}

The problem is this transfer is only one way and it only transfers files whereas I would like to implement it into my pvp card game application code to transfer ArrayList objects BOTH ways. 问题是这种转移只是一种方式而且它只传输文件,而我想将它实现到我的pvp卡游戏应用程序代码中以传输ArrayList对象两种方式。 How can I do this? 我怎样才能做到这一点?

Also how can I transfer the current "ArrayList deck" that I have instantiated there to begin with? 另外,我如何转移我在那里开始实例化的当前“ArrayList deck”? I won't need to search, I'll know my ArrayList's name from inside the code. 我不需要搜索,我会从代码中知道我的ArrayList的名字。

I'm not going out of my way to code you a solution, and you've probably already found the solution to your problem. 我不会忘记为您编写解决方案,您可能已经找到了解决问题的方法。 But just in case you haven't: 但万一你没有:

Sending an ArrayList<String> from the server side to the client side over TCP using socket? 使用套接字通过TCP从服务器端向客户端发送ArrayList <String>?

The link above seems to cover your ArrayList via socket issue. 上面的链接似乎通过套接字问题覆盖了您的ArrayList。 One comment suggested you might be better sending primitive strings and then making an array on the other end. 一条评论建议您最好发送原始字符串,然后在另一端创建数组。 Wi-Fi Direct's bandwidth should easily handle this, but then, it should also handle an ArrayList transfer too. Wi-Fi Direct的带宽应该很容易处理,但是,它也应该处理ArrayList传输。

In regards to a two way connection, I will link you to this , which certainly got me started in understanding two way sockets on Android, input and output streams, etc. Be advised to also read up on sockets in Oracles documentation . 在问候双向连接,我会联系你这个 ,这当然让我了解在Android上,输入和输出流等双向插座开始,宜在插座还阅读了甲骨文的文档

Wi-Fi Direct is still very much in its infancy. Wi-Fi Direct仍然处于起步阶段。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM