public class UploadServiceBroadcastReceiver extends BroadcastReceiver
UploadService
events.
It provides the boilerplate code to properly handle broadcast messages coming from the
upload service and dispatch them to the proper handler method.BroadcastReceiver.PendingResult
Constructor and Description |
---|
UploadServiceBroadcastReceiver() |
Modifier and Type | Method and Description |
---|---|
void |
onCancelled(String uploadId)
Called when the upload is cancelled.
|
void |
onCompleted(String uploadId,
int serverResponseCode,
byte[] serverResponseBody)
Called when the upload is completed successfully.
|
void |
onError(String uploadId,
Exception exception)
Called when an error happens during the upload.
|
void |
onProgress(String uploadId,
int progress)
Called when the upload progress changes.
|
void |
onProgress(String uploadId,
long uploadedBytes,
long totalBytes)
Called when the upload progress changes.
|
void |
onReceive(Context context,
Intent intent) |
void |
register(Context context)
Register this upload receiver.
If you use this receiver in an Activity , you have to call this method inside
Activity.onResume() , after super.onResume(); .If you use it in a Service , you have to
call this method inside Service.onCreate() , after super.onCreate(); . |
void |
unregister(Context context)
Unregister this upload receiver.
If you use this receiver in an Activity , you have to call this method inside
Activity.onPause() , after super.onPause(); .If you use it in a Service , you have to
call this method inside Service.onDestroy() . |
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
public void onReceive(Context context, Intent intent)
onReceive
in class BroadcastReceiver
public void register(Context context)
Activity
, you have to call this method inside
Activity.onResume()
, after super.onResume();
.Service
, you have to
call this method inside Service.onCreate()
, after super.onCreate();
.context
- context in which to register this receiverpublic void unregister(Context context)
Activity
, you have to call this method inside
Activity.onPause()
, after super.onPause();
.Service
, you have to
call this method inside Service.onDestroy()
.context
- context in which to unregister this receiverpublic void onProgress(String uploadId, int progress)
uploadId
- unique ID of the upload requestprogress
- value from 0 to 100public void onProgress(String uploadId, long uploadedBytes, long totalBytes)
uploadId
- unique ID of the upload requestuploadedBytes
- the count of the bytes uploaded so fartotalBytes
- the total expected bytes to uploadpublic void onError(String uploadId, Exception exception)
uploadId
- unique ID of the upload requestexception
- exception that caused the errorpublic void onCompleted(String uploadId, int serverResponseCode, byte[] serverResponseBody)
uploadId
- unique ID of the upload requestserverResponseCode
- status code returned by the serverserverResponseBody
- byte array containing the response body received from the server.
If your server responds with a string, you can get it with
new String(serverResponseBody)
. If the string is a
JSON, you can parse it using a library such as org.json
(embedded in Android) or google's gsonpublic void onCancelled(String uploadId)
uploadId
- unique ID of the upload request