Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 934d4e0

Browse files
author
Alex Gotev
committed
Update README.md
Updated usage example
1 parent 8afec66 commit 934d4e0

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

README.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,23 @@ Add the following to your project's AndroidManifest.xml file:
3131

3232
## How to start android upload service to upload files
3333
public void updateSomething(final Context context) {
34-
//The full URL to your server side HTTP multipart upload script
35-
final String serverUrl = "http://www.yourcompany.com/your/upload/script";
36-
37-
final ArrayList<FileToUpload> files = new ArrayList<FileToUpload>();
38-
files.add(new FileToUpload("/absolute/path/to/your/file",
39-
"http-form-parameter-name",
40-
"content-type")); //You can find many common content types defined as static constants in the ContentType class
41-
42-
//This is optional. If you don't want to add any specific headers, you can just leave the list empty
43-
final ArrayList<NameValue> headers = new ArrayList<NameValue>();
44-
headers.add(new NameValue("additional-header-name", "additional-header-value"));
45-
46-
final ArrayList<NameValue> parameters = new ArrayList<NameValue>();
47-
parameters.add(new NameValue("parameter-name", "parameter-value"));
34+
final UploadRequest request = new UploadRequest(context, "http://www.yourcompany.com/your/upload/script");
35+
36+
request.addFileToUpload("/absolute/path/to/your/file",
37+
"parameter-name",
38+
"content-type")); //You can find many common content types defined as static constants in the ContentType class
39+
40+
//You can add your own custom headers
41+
request.addHeader("your-custom-header", "your-custom-value");
42+
43+
request.addParameter("parameter-name", "parameter-value");
4844
4945
//If you want to add an array of strings, you can simply to the following:
50-
parameters.add(new NameValue("array-parameter-name", "value1"));
51-
parameters.add(new NameValue("array-parameter-name", "value2"));
52-
parameters.add(new NameValue("array-parameter-name", "valueN"));
53-
54-
UploadNotificationConfig notificationConfig =
55-
new UploadNotificationConfig(
46+
request.addParameter("array-parameter-name", "value1");
47+
request.addParameter("array-parameter-name", "value2");
48+
request.addParameter("array-parameter-name", "valueN");
49+
50+
request.setNotificationConfig(
5651
android.R.drawable.ic_menu_upload, //Notification icon. You can use your own app's R.drawable.your_resource
5752
"notification title", //You can use your string resource with: context.getString(R.string.your_string)
5853
"upload in progress text",
@@ -63,10 +58,9 @@ Add the following to your project's AndroidManifest.xml file:
6358
try {
6459
//Utility method that creates the intent and starts the upload service in the background
6560
//As soon as the service starts, you'll see upload status in Android Notification Center :)
66-
UploadService.startUpload(context, notificationConfig, serverUrl, files, headers, parameters);
67-
61+
UploadService.startUpload(request);
6862
} catch (Exception exc) {
69-
//You will end up here only if you pass null parameters or an invalid server URL
63+
//You will end up here only if you pass an incomplete UploadRequest
7064
Log.e("AndroidUploadService", exc.getLocalizedMessage(), exc);
7165
}
7266
}

0 commit comments

Comments
 (0)