Reputation: 53
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:
// 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);
The problem is this 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. How can I do this? I would like to NOT transfer txt files and have a file buffer in my code. I have not found any good tutorials that show how this wifi-direct connectivity can be incorporated into a larger app.
Upvotes: 2
Views: 1346
Reputation: 41
I am also kinda new to this topic (Android and especialy Wi-Fi DIrect p2p) but i think it transfers bytes. So if you transfer your ArrayList to an array of bytes, like this:
byte[] result = new byte[list.size()];
for(int i=0; i<list.size; i++){
result[i] = list.get(i).byteValue();
}
you may succed.
Note that to code you posted does not do the actuall transfer, it just lets the user select an image from the gallery. I can`t point you to the exact pice of code that does the transfer (noobie me) but I think it uses som OutputStram-s.
Upvotes: 1