Class SAFileTransfer
- java.lang.Object
-
- com.samsung.android.sdk.accessoryfiletransfer.SAFileTransfer
-
public class SAFileTransfer extends java.lang.Object
SAFileTransfer provides the main interface to exchange a file between the Accessory Peer Agents. To access the Accessory File Transfer methods, the application must acquire an instance of this class.Developer Guides
The application also has to define a Broadcast Receiver for the
ACTION_SAP_FILE_TRANSFER_REQUESTED
action on the file receiver side for the files to be received.To acquire an instance of this class, the application must have an
SAAgent
implementation and aSAFileTransfer.EventListener
implementation.For more information about using Accessory File Transfer, please refer to the Accessory Programming Guide.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static interface
SAFileTransfer.EventListener
Provides callbacks invoked when messages related to the file transfer transaction are received.
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String
ACTION_SAP_FILE_TRANSFER_REQUESTED
Broadcast Action: Indicates an incoming file transfer request has been received.static int
ERROR_CHANNEL_IO
Sending or receiving a file failed as the Samsung Accessory Service Framework failed to send or receive the file.static int
ERROR_COMMAND_DROPPED
Receiving a file failed as a request was made in an invalid state.static int
ERROR_CONNECTION_LOST
Sending or receiving a file failed as the Service Connection with the connected Peer Agent was lost. *Note: In this case, the sender application should check if the Accessory device has been detached or not.
static int
ERROR_FATAL
Fatal error occurred.static int
ERROR_FILE_IO
Sending or receiving a file failed as relevant file failed in reading or writing.static int
ERROR_NONE
File transfer succeeded.static int
ERROR_NOT_SUPPORTED
Called method is not supported by Samsung Accessory File Transfer Service.static int
ERROR_PEER_AGENT_BUSY
Sending a file failed as the receiver Peer Agent was already busy receiving another file.static int
ERROR_PEER_AGENT_NO_RESPONSE
Sending or receiving a file failed as the connected Peer Agent was not responding.static int
ERROR_PEER_AGENT_REJECTED
Sending a file failed as the connected Peer Agent rejected or cancelled the file transfer.static int
ERROR_REQUEST_NOT_QUEUED
Sending a file failed as the Samsung Accessory Service Framework failed to queue the sending file request.static int
ERROR_SPACE_NOT_AVAILABLE
Sending a file failed as the connected Peer Agent did not have enough free space available.static int
ERROR_TRANSACTION_NOT_FOUND
Canceling all transactions failed as there were no transactions being executed for the application.
-
Constructor Summary
Constructors Constructor and Description SAFileTransfer(SAAgent callingAgent, SAFileTransfer.EventListener eventListener)
Creates an SAFileTransfer instance with the specifiedSAAgent
andSAFileTransfer.EventListener
instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
cancel(int transactionId)
Cancels an ongoing file transfer.void
cancelAll()
Cancels all sending file transactions including ongoing and queued file transfer requests.void
close()
Closes the bound connection with Accessory File Transfer Service and cleans up any resources it holds.void
receive(int transactionId, java.lang.String path)
Accepts a file transfer from a connected Peer Agent.void
reject(int transactionId)
Rejects a file transfer from a connected Peer Agent.int
send(SAPeerAgent peerAgent, java.lang.String source)
Sends a file to a connected Peer Agent.
-
-
-
Field Detail
-
ERROR_NONE
public static final int ERROR_NONE
File transfer succeeded.- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_REQUEST_NOT_QUEUED
public static final int ERROR_REQUEST_NOT_QUEUED
Sending a file failed as the Samsung Accessory Service Framework failed to queue the sending file request.Possibly because the file transfer peer could not be found or the peer found has a different accessory id than the one provided by the application. *
Note: The sender application should not retry sending the file in this case.
Constant Value: -1 (0xFFFFFFFF)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_CHANNEL_IO
public static final int ERROR_CHANNEL_IO
Sending or receiving a file failed as the Samsung Accessory Service Framework failed to send or receive the file.Constant Value: 1 (0x00000001)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_FILE_IO
public static final int ERROR_FILE_IO
Sending or receiving a file failed as relevant file failed in reading or writing.Constant Value: 2 (0x00000002)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_COMMAND_DROPPED
public static final int ERROR_COMMAND_DROPPED
Receiving a file failed as a request was made in an invalid state.Constant Value: 3 (0x00000003)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_PEER_AGENT_NO_RESPONSE
public static final int ERROR_PEER_AGENT_NO_RESPONSE
Sending or receiving a file failed as the connected Peer Agent was not responding.Constant Value: 4 (0x00000004)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_CONNECTION_LOST
public static final int ERROR_CONNECTION_LOST
Sending or receiving a file failed as the Service Connection with the connected Peer Agent was lost. *Note: In this case, the sender application should check if the Accessory device has been detached or not. If detached, it should not retry sending the file.
Constant Value: 5 (0x00000005)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_PEER_AGENT_BUSY
public static final int ERROR_PEER_AGENT_BUSY
Sending a file failed as the receiver Peer Agent was already busy receiving another file.Constant Value: 8 (0x00000008)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_PEER_AGENT_REJECTED
public static final int ERROR_PEER_AGENT_REJECTED
Sending a file failed as the connected Peer Agent rejected or cancelled the file transfer.Constant Value: 9 (0x00000009)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_SPACE_NOT_AVAILABLE
public static final int ERROR_SPACE_NOT_AVAILABLE
Sending a file failed as the connected Peer Agent did not have enough free space available.Constant Value: 11 (0x0000000B)
- Since:
- 2.0.19
- See Also:
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
, Constant Field Values
-
ERROR_NOT_SUPPORTED
public static final int ERROR_NOT_SUPPORTED
Called method is not supported by Samsung Accessory File Transfer Service.Note: Several methods are not supported by installed Samsung Accessory File Transfer Service. It's recommended to upgrade it to 2.16.xx or above.
Constant Value: 12 (0x0000000C)
- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
ERROR_TRANSACTION_NOT_FOUND
public static final int ERROR_TRANSACTION_NOT_FOUND
Canceling all transactions failed as there were no transactions being executed for the application.Constant Value: 13 (0x0000000D)
- Since:
- 2.3.0
- See Also:
- Constant Field Values
-
ERROR_FATAL
public static final int ERROR_FATAL
Fatal error occurred. For example, a binding failure occurred or Samsung Accessory Service Framework died.Constant Value: 2048 (0x00000800)
- Since:
- 2.3.2
- See Also:
- Constant Field Values
-
ACTION_SAP_FILE_TRANSFER_REQUESTED
public static final java.lang.String ACTION_SAP_FILE_TRANSFER_REQUESTED
Broadcast Action: Indicates an incoming file transfer request has been received.Note:The broadcast receiver must be registered in the receiving application's manifest file.
<application ... <receiver android:name="com.samsung.android.sdk.accessoryfiletransfer.SAFileTransferIncomingRequestReceiver"> <intent-filter> <action android:name="com.samsung.accessory.ftconnection" /> </intent-filter> </receiver> ... </application>
Constant Value: "com.samsung.accessory.ftconnection"
- Since:
- 2.0.19
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SAFileTransfer
public SAFileTransfer(SAAgent callingAgent, SAFileTransfer.EventListener eventListener)
Creates an SAFileTransfer instance with the specifiedSAAgent
andSAFileTransfer.EventListener
instances.- Parameters:
callingAgent
- The SAAgent instance of the calling application.eventListener
- The listener instance- Throws:
java.lang.IllegalArgumentException
- Thrown if any of the parameters passed are null.- Since:
- 2.0.19
-
-
Method Detail
-
send
public int send(SAPeerAgent peerAgent, java.lang.String source)
Sends a file to a connected Peer Agent.Note: The file is sent asynchronously by the Accessory File Transfer implementation on its own.
- Parameters:
peerAgent
- The remote Peer Agent to receive the file.source
- The source file path.- Returns:
- Transaction ID of the sending file request.
-1
if the request could not be processed as the application's data was cleared. Application should be registered again in this case. - Throws:
java.lang.IllegalArgumentException
- Thrown if the file path passed is invalid, the file does not exist in the specified path, the file size is zero, or the peer agent passed is null.- Since:
- 2.0.19
-
receive
public void receive(int transactionId, java.lang.String path)
Accepts a file transfer from a connected Peer Agent.- Parameters:
transactionId
- The transaction ID given by the Accessory File Transfer Servicepath
- The path where the file is stored.- Throws:
java.lang.IllegalArgumentException
- Thrown if the given file path or transaction ID passed is invalid.- Since:
- 2.0.19
-
reject
public void reject(int transactionId)
Rejects a file transfer from a connected Peer Agent.- Parameters:
transactionId
- The transaction ID given by the Accessory File Transfer Service.- Throws:
java.lang.IllegalArgumentException
- Thrown if the transaction ID passed is invalid.- Since:
- 2.0.19
-
cancel
public void cancel(int transactionId)
Cancels an ongoing file transfer. Both the sender and receiver of the file can call this method.- Parameters:
transactionId
- The transaction ID of the file transfer request- Throws:
java.lang.IllegalArgumentException
- Thrown if the transaction ID passed is invalid- Since:
- 2.0.19
-
cancelAll
public void cancelAll()
Cancels all sending file transactions including ongoing and queued file transfer requests.Note: This method should be called only by the sender Peer Agent. This method does not affect receiving file transactions. This method is supported from Samsung Accessory Service Framework ver.2.16.xx or higher. Otherwise you will get
ERROR_NOT_SUPPORTED
.- Since:
- 2.3.0
-
close
public void close()
Closes the bound connection with Accessory File Transfer Service and cleans up any resources it holds.Note: This method should only be called when the application have no use of Accessory File Transfer Service. It means this method should never be called in case that there is an ongoing file transfer transaction. Once this method is called, the application won't be able receive or send files until it creates a new
SAFileTransfer
instance.public SAFileTransfer createNewFileTransfer(){ mFileTransfer = new SAFileTransfer(callingAgent, listener); return mFileTransfer; }
- Since:
- 2.3.0
-
-