See Releases for more details.
Please issue your API key from following link first: https://send-anywhere.com/web/page/api
Send Anywhere Android SDK is available via both jcenter()
and mavenCentral()
.
Just add the following line to your gradle dependency:
implementation ('com.estmob.android:sendanywhere:11.1.22@aar') {
transitive = true
}
Add android:requestLegacyExternalStorage="true" to AndroidManifest.xml.
<application
android:requestLegacyExternalStorage="true" >
</application>
If you have any problem or questions with Send Anywhere Android SDK, please create new issue(https://github.com/estmob/SendAnywhere-Android-SDK/issues) or contact to our customer center(https://send-anywhere.zendesk.com).
If your are using Proguard and it complains during complie, refer Proguard rules in sample app.
From Android Marshmallow(API 23), Android introduced new way to handle application permissions, called "Runtime Permissions". This requires developers to request sensitive permissions to users explicitly in application runtime. Send Anywhere SDK requires external storage permissions(android.permission.WRITE_EXTERNAL_STORAGE
, android.permission.READ_EXTERNAL_STORAGE
) to work properly, but does NOT handle these permissions automatically. Please refer these articles to see more about Runtime Permission Model:
- Requesting Permissions at Run Time (Android Developers) - https://developer.android.com/training/permissions/requesting.html
- Exploring the new Android Permissions Model (Ribot labs) - https://labs.ribot.co.uk/exploring-the-new-android-permissions-model-ba1d5d6c0610#.95cppknud
You must call Task.init("YOUR_API_KEY")
proceeding any transfer operations, e.g. onCreate
of Activity
. It is declared as static
, so you just have to call it once.
If this problem persists, please contact us to re-issue your api-key.
Send Anywhere SDK uses play-services-ads-identifier
internally.
If this conflicts with your play-services
dependency, please exclude play-services
module used in our SDK:
compile ('com.estmob.android:sendanywhere:x.x.x@aar') {
exclude module: "play-services-ads-identifier"
transitive = true
}
First look at the source code of the provided demo.
public class SendTask extends Task {
public SendTask(Context context, File[] files);
public SendTask(Context context, List<? extends FileInfo> files);
public SendTask(Context context, File[] files, boolean uploadMode);
public SendTask(Context context, List<? extends FileInfo> files, boolean uploadMode);
public interface FileInfo {
@NonNull Uri getUri();
@NonNull String getFileName();
long getLength();
long getLastModified();
}
...
}
public class ReceiveTask extends Task {
public ReceiveTask(Context context, String key, File destDir);
...
}
Parameters | |
---|---|
context | The current context. |
files | The file list what you want to send. |
Parameters | |
---|---|
context | The current context. |
files | The file list with your own implementation of SendTask.FileInfo |
You can provide your own implementation of SendTask.FileInfo
for non-traditional files that cannot be represented as Java.io.File
, such as files starting with content://..
See SimpleFileInfo in sample for the example implementaion.
Methods | Return type | |
---|---|---|
getUri | Uri | The Uri of sending file. |
getFileName | String | The file name for recevier. |
getLength | long | The length of sending file. |
getLastModified | long | The last modified time in seconds |
Parameters | |
---|---|
context | The current context. |
files | The file list what you want to send. |
uploadMode | Set to true to enable upload mode. |
In upload mode, the receiver can receive the file using the key or URL after the file transfer is completed.
Parameters | |
---|---|
context | The current context. |
files | The file list with your own implementation of SendTask.FileInfo |
uploadMode | Set to true to enable upload mode. |
Parameters | |
---|---|
context | The current context. |
key | The KEY of sender. |
destDir | The folder to save files. |
public class Task {
...
public static void init(String key);
public static void setProfileName(String name);
public void start();
public void await();
public void cancel();
public Object getValue();
...
}
Set your API key.
Parameters | |
---|---|
key | Your API Key. |
Set profile name of the device
Parameters | |
---|---|
name | Desired device name |
Start task for sending or receiving.
Wait until task is finished.
Cancel the task to stop.
Fetch additional information of Task
. You should cast return Object
to vaild types for each cases.
public static class Value {
public static final int KEY;
public static final int EXPIRES_TIME;
}
Task.Value (key) | Task.DetailedState (available on) | Type |
---|---|---|
KEY | PREPARING_UPDATED_KEY | String |
EXPIRES_TIME | PREPARING_UPDATED_KEY | long (UNIX Epoch time in seconds) |
public class Task {
...
public interface OnTaskListener {
void onNotify(int state, int detailedState, Object obj);
}
public void setOnTaskListener(OnTaskListener callback)
...
}
public class Task {
public static class State {
public static final int UNKNOWN;
public static final int FINISHED;
public static final int ERROR;
public static final int PREPARING;
public static final int TRANSFERRING;
}
public static class DetailedState {
public static final int UNKNOWN;
public static final int FINISHED_SUCCESS;
public static final int FINISHED_CANCEL;
public static final int FINISHED_ERROR;
public static final int ERROR_WRONG_API_KEY;
public static final int ERROR_SERVER;
public static final int PREPARING_UPDATED_KEY;
public static final int PREPARING_UPDATED_FILE_LIST;
public static final int TRANSFERRING;
}
...
}
public class SendTask extends Task {
public static class DetailedState extends Task.DetailedState {
public static final int ERROR_NO_REQUEST;
}
...
}
public class ReceiveTask extends Task {
public static class DetailedState extends Task.DetailedState {
public static final int ERROR_NO_EXIST_KEY;
public static final int ERROR_FILE_NO_DOWNLOAD_PATH;
public static final int ERROR_FILE_NO_DISK_SPACE;
public static final int ERROR_FILE_DISK_NOT_MOUNTED;
}
...
}
Register a callback to be invoked when transfer event occurs.
Task.State | Task.DetailedState | param |
---|---|---|
FINISHED | FINISHED_SUCCESS |
| FINISHED_CANCEL | |
| FINISHED_ERROR | |
ERROR | ERROR_WRONG_API_KEY | | | ERROR_SERVER | | | ERROR_NO_REQUEST | | | ERROR_NO_EXIST_KEY | | | ERROR_FILE_NO_DOWNLOAD_PATH | | | ERROR_FILE_NO_DISK_SPACE | | | ERROR_FILE_DISK_NOT_MOUNTED | | PREPARING | PREPARING_UPDATED_KEY | String | | PREPARING_UPDATED_FILE_LIST | Task.FileState[]| TRANSFERRING | TRANSFERRING | Task.FileState |
Flow Step
- PREPARING_UPDATED_KEY
- PREPARING_UPDATED_FILE_LIST
- TRANSFERRING
- TRANSFERRING
- ...
- TRANSFERRING
- TRANSFERRING
- FINISHED_SUCCESS
- FINISHED_CANCEL
- ERROR
- FINISHED_ERROR
- PREPARING_UPDATED_FILE_LIST
public class Task {
...
public static class FileSate {
public File getFile();
public String getPathName();
public long getTransferSize();
public long getTotalSize();
}
...
}
Return the File object.
Return the relative path and file name.
Returns the transfer size in bytes.
Return the size of the file in bytes.