4

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. 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. How can I do this?

Also how can I transfer the current "ArrayList deck" that I have instantiated there to begin with? I won't need to search, I'll know my ArrayList's name from inside the code.

Adolphin
  • 62
  • 4

1 Answers1

0

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?

The link above seems to cover your ArrayList via socket issue. 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.

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.

Wi-Fi Direct is still very much in its infancy. Good luck.

Community
  • 1
  • 1
Chucky
  • 1,701
  • 7
  • 28
  • 62