com.samsung.android.sdk.accessoryfiletransfer

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 a SAFileTransfer.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.
    • 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.
    • Constructor Detail

      • SAFileTransfer

        public SAFileTransfer(SAAgent callingAgent,
                              SAFileTransfer.EventListener eventListener)
        Creates an SAFileTransfer instance with the specified SAAgent and SAFileTransfer.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 Service
        path - 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