androidandroid-wifiwifi-directfile-sharinglogan-square

How should I share Files using WiFi Direct to another android device?? - Salut and LoganSquare


**

SITUATION IS -

**

  1. I am creating an application that shares files between android devices.
  2. I use Salut as a WiFi Direct Wrapper.
  3. Salut uses LoganSquare for sharing data between peers connected via WiFi Direct.

My Objective : How should I share Files using WiFi Direct to another android device??

Some what like ShareIt, Superbeam, Xender etc..

(It is my project to create, process a file, and send it over WiFi to peers.)


Solution

  • Okay, for devs facing similar issues. I figured out the answer.

    Salut works well with LoganSquare except that it needs data to be serialized to send to other devices. To send files, we can contain them in a seralizable class as a String field of the class as Strings are serializable.

    HOW TO DO THAT?

    1. Load the file in FileOutputStream
    2. Convert it to ByteArrayOutputStream
    3. Then convert it to String

    BUT I HAVE A HUGE file! How much would the capacity of the String be?

    No worries!

    String can store up to (2^31)-1 characters (Integer.MAX_VALUE)

    Calculations -

    1. (2^31)-1 = 2,147,483,648 characters
    2. Assuming Java takes 2 bytes for a character : 2,147,483,648 characters = 2,147,483,648/2 = 1,073,741,824 bytes = 1,048,576 KB = 1024 MB = 1 GB

    (or simple 1KB = 2^10 bytes , 1MB = 2^20 bytes, 1GB = 2^30 bytes )

    Are you going to send a file more than 1 GB size ?

    If yes, you can use a String[ ].

    Problems on security ?

    You can encrypt the file before sending !