You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* a demo server-side php script that handles multipart form upload
47
-
* a simple demo application that uses this library
52
+
* a simple demo application that uses this library
48
53
49
54
To be able to compile and deploy the demo application, you also need to have <b>appcompat_v7</b> library. You may need to change the path to that library in the demo application's properties.
50
55
51
56
## How to start android upload service to upload files
52
57
For detailed explanation of each parameter, please check JavaDocs.
53
58
54
59
public void upload(final Context context) {
55
-
final UploadRequest request = new UploadRequest(context,
56
-
"custom-upload-id",
60
+
final UploadRequest request = new UploadRequest(context,
61
+
"custom-upload-id",
57
62
"http://www.yoursite.com/yourscript");
58
63
59
64
/*
60
-
* parameter-name: is the name of the parameter that will contain file's data.
65
+
* parameter-name: is the name of the parameter that will contain file's data.
61
66
* Pass "uploaded_file" if you're using the test PHP script
62
67
*
63
-
* custom-file-name.extension: is the file name seen by the server.
68
+
* custom-file-name.extension: is the file name seen by the server.
64
69
* E.g. value of $_FILES["uploaded_file"]["name"] of the test PHP script
Once the service is started, it publishes the upload status with broadcast intents.
113
-
For the sake of simplicity and to not bother you with the writing of a broadcast receiver,
117
+
Once the service is started, it publishes the upload status with broadcast intents.
118
+
For the sake of simplicity and to not bother you with the writing of a broadcast receiver,
114
119
an abstract broadcast receiver has been implemented for you and you just need to extend it and add your custom code.
115
120
So to listen for the status of the upload service in an Activity for example, you just need to do the following:
116
121
117
122
public class YourActivity extends Activity {
118
-
123
+
119
124
private static final String TAG = "AndroidUploadService";
120
-
125
+
121
126
...
122
-
123
-
private final AbstractUploadServiceReceiver uploadReceiver =
127
+
128
+
private final AbstractUploadServiceReceiver uploadReceiver =
124
129
new AbstractUploadServiceReceiver() {
125
130
126
131
@Override
127
132
public void onProgress(String uploadId, int progress) {
128
-
Log.i(TAG, "The progress of the upload with ID "
133
+
Log.i(TAG, "The progress of the upload with ID "
129
134
+ uploadId + " is: " + progress);
130
135
}
131
136
132
137
@Override
133
138
public void onError(String uploadId, Exception exception) {
134
-
Log.e(TAG, "Error in upload with ID: " + uploadId + ". "
139
+
Log.e(TAG, "Error in upload with ID: " + uploadId + ". "
135
140
+ exception.getLocalizedMessage(), exception);
136
141
}
137
142
138
143
@Override
139
144
public void onCompleted(String uploadId,
140
-
int serverResponseCode,
145
+
int serverResponseCode,
141
146
String serverResponseMessage) {
142
-
Log.i(TAG, "Upload with ID " + uploadId
143
-
+ " is completed: " + serverResponseCode
147
+
Log.i(TAG, "Upload with ID " + uploadId
148
+
+ " is completed: " + serverResponseCode
144
149
+ ", " + serverResponseMessage);
145
150
}
146
151
};
147
-
152
+
148
153
@Override
149
154
protected void onResume() {
150
155
super.onResume();
151
156
uploadReceiver.register(this);
152
157
}
153
-
158
+
154
159
@Override
155
160
protected void onPause() {
156
161
super.onPause();
157
162
uploadReceiver.unregister(this);
158
163
}
159
-
164
+
160
165
}
161
166
162
167
If you want to monitor upload status in all of your activities, then just implement the BroadcastReceiver in your base activity class, from which all of your activities inherits and you're done.
@@ -165,14 +170,14 @@ If you want to monitor upload status in all of your activities, then just implem
165
170
For security reasons, the library doesn't accept self-signed certificates by default when using HTTPS connections, but you can enable them by calling:
166
171
167
172
AllCertificatesAndHostsTruster.apply();
168
-
173
+
169
174
before starting the upload service.
170
175
171
176
## Do you use Android Upload Service in your project?
172
177
Let me know, and I'll be glad to include a link in the following list :)
173
178
174
179
-[VoiSmart IP Communicator](https://play.google.com/store/apps/details?id=com.voismart.softphone)
0 commit comments