public class SAFileTransfer
extends java.lang.Object
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.
Modifier and Type | Class and Description |
---|---|
static interface |
SAFileTransfer.EventListener
Provides callbacks invoked when messages related to the file transfer transaction are received.
|
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 and Description |
---|
SAFileTransfer(SAAgent callingAgent,
SAFileTransfer.EventListener eventListener)
Creates an SAFileTransfer instance with the specified
SAAgent and SAFileTransfer.EventListener instances. |
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.
|
public static final int ERROR_NONE
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_REQUEST_NOT_QUEUED
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)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_CHANNEL_IO
Constant Value: 1 (0x00000001)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_FILE_IO
Constant Value: 2 (0x00000002)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_COMMAND_DROPPED
Constant Value: 3 (0x00000003)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_PEER_AGENT_NO_RESPONSE
Constant Value: 4 (0x00000004)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_CONNECTION_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)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_PEER_AGENT_BUSY
Constant Value: 8 (0x00000008)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_PEER_AGENT_REJECTED
Constant Value: 9 (0x00000009)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_SPACE_NOT_AVAILABLE
Constant Value: 11 (0x0000000B)
SAFileTransfer.EventListener.onTransferCompleted(int, String, int)
,
Constant Field Valuespublic static final int ERROR_NOT_SUPPORTED
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)
public static final int ERROR_TRANSACTION_NOT_FOUND
Constant Value: 13 (0x0000000D)
public static final int ERROR_FATAL
Constant Value: 2048 (0x00000800)
public static final java.lang.String ACTION_SAP_FILE_TRANSFER_REQUESTED
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"
public SAFileTransfer(SAAgent callingAgent, SAFileTransfer.EventListener eventListener)
SAAgent
and SAFileTransfer.EventListener
instances.callingAgent
- The SAAgent instance of the calling application.eventListener
- The listener instancejava.lang.IllegalArgumentException
- Thrown if any of the parameters passed are null.public int send(SAPeerAgent peerAgent, java.lang.String source)
Note: The file is sent asynchronously by the Accessory File Transfer implementation on its own.
peerAgent
- The remote Peer Agent to receive the file.source
- The source file path.-1
if the request could not be processed as the
application's data was cleared. Application should be registered again in this case.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.public void receive(int transactionId, java.lang.String path)
transactionId
- The transaction ID given by the Accessory File Transfer Servicepath
- The path where the file is stored.java.lang.IllegalArgumentException
- Thrown if the given file path or transaction ID passed is invalid.public void reject(int transactionId)
transactionId
- The transaction ID given by the Accessory File Transfer Service.java.lang.IllegalArgumentException
- Thrown if the transaction ID passed is invalid.public void cancel(int transactionId)
transactionId
- The transaction ID of the file transfer requestjava.lang.IllegalArgumentException
- Thrown if the transaction ID passed is invalidpublic void cancelAll()
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
.
public void close()
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;
}
Copyright © Samsung Electronics, Co., Ltd. All rights reserved.