Category: Data, github

When you transfer a file to your friend using a mobile phone, the progress seems never to reach the end. Finally, the transfer ends, but a single file has exhausted your mobile data.

Both parties must accept the connection by calling acceptConnect() or reject the connection by calling rejectConnect().

You can call sendData() to send data and call onReceived() of DataCallback to receive data.BYTES You can call Data.fromBytes() to create a data object of the Data.Type.BYTES type.The following is the sample code for sending byte arrays:Note: The size of byte arrays cannot exceed 32 KB.The following is the sample code for receiving byte arrays:Note: Different from data of FILE and STREAM types, data of the BYTES type is sent as chunks, and the subscriber does not need to wait for the TRANSFER_STATE_SUCCESS status code. When onReceived() is called, you can call data.asBytes() to obtain the full data.FILEYou can call Data.fromFile() to create a data object of the Data.Type.FILE type.The following is the sample code for sending a file:To be more efficient, you can create a FILE type using ParcelFileDescriptor, which minimizes file replication.Sample code:When a file is received, it is saved in the Download directory on the subscriber's device with the name defined as the character string converted by fileData.getId().

Related Articles