Class MessageHandler
- All Implemented Interfaces:
Handler.Callback
ACTION_DOWNLOAD_STOPPED
ACTION_DOWNLOAD_CREATED
ACTION_DOWNLOAD_STARTED
ACTION_DOWNLOAD_DELETED
ACTION_DOWNLOAD_COMPLETED
ACTION_DOWNLOAD_NO_PENDING
ACTION_DOWNLOAD_ERROR
ACTION_DOWNLOAD_STORAGE_LOW
ACTION_DOWNLOAD_STORAGE_OK
ACTION_DOWNLOAD_PROGRESS
ACTION_DOWNLOAD_PATH_UPDATE
IntentFilter filter = new IntentFilter();
filter.addCategory(MessageHandler.INTENT_DOWNLOAD_CATEGORY);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_ERROR);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_STOPPED);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_CREATED);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_STARTED);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_DELETED);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_COMPLETED);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_NO_PENDING);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_STORAGE_OK);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_STORAGE_LOW);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_PROGRESS);
filter.addAction(MessageHandler.ACTION_DOWNLOAD_PATH_UPDATE);
LocalBroadcastManager.getInstance(context).registerReceiver(new BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
String downloadId = intent.getStringExtra(MessageHandler.INTENT_DOWNLOAD_ID);
Log.d(TAG, "Message: " + intent.getAction() + ", download Id: " + downloadId);
switch (intent.getAction()) {
case MessageHandler.ACTION_DOWNLOAD_STOPPED:
break;
case MessageHandler.ACTION_DOWNLOAD_CREATED:
break;
case MessageHandler.ACTION_DOWNLOAD_STARTED:
break;
case MessageHandler.ACTION_DOWNLOAD_DELETED:
break;
case MessageHandler.ACTION_DOWNLOAD_COMPLETED:
break;
case MessageHandler.ACTION_DOWNLOAD_NO_PENDING:
break;
case MessageHandler.ACTION_DOWNLOAD_ERROR:
break;
case MessageHandler.ACTION_DOWNLOAD_STORAGE_LOW:
break;
case MessageHandler.ACTION_DOWNLOAD_STORAGE_OK:
break;
case MessageHandler.ACTION_DOWNLOAD_PROGRESS:
break;
case MessageHandler.ACTION_DOWNLOAD_PATH_UPDATE:
break;
default:
break;
}
}
}, filter);
Error handling
The intent bundle that is send with broadcast messages always contains theINTENT_DOWNLOAD_ID
parameter, which is the download ID String
. In addition, all ACTION_DOWNLOAD_ERROR
messages contain the INTENT_DOWNLOAD_ERROR
String
, which is a string representation
that contains the message from the exception that occurred during the download. Because all intent parameters
need to be parcelable, we can unfortunately not embed the original Exception.
Since version 4.1.5, error message also contain additional data. INTENT_DOWNLOAD_ERROR_TYPE
contains the error type, which is one of the ERROR_*
constants of this class. Some of the
error types might contains additional information. You can check for the http status code under the
INTENT_DOWNLOAD_ERROR_HTTP_STATUS
key. The URL that caused the error can be checked
with INTENT_DOWNLOAD_ERROR_HTTP_URL
. Both of these values are optional and we might not
be able to report them for all errors.
ERROR_TYPE_CONNECTION_ERROR
when the
underlying socket connection is interrupted. That can happen for instance when the device
looses its connectivity.
DRM errors are reported as ERROR_TYPE_DRM_ERROR
if there was a problem while fetching
the offline license. The underlying DRM error code can be queried through the
INTENT_DOWNLOAD_ERROR_DRM
key, which will contain one of the values defined in the
constants starting with ERROR_*
in DrmTodayException
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been completedstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been createdstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been deletedstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download error occurredstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that the download queue has no started downloadsstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that the path for a download has been updated, or failed to.static final String
Use this as action inIntentFilter.addAction(String)
to receive messages that progress was made on the current downloadstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been startedstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been stoppedstatic final String
Use this as action inIntentFilter.addAction(String)
to receive messages that the storage is insufficient to continue with downloads If this action is fired all ongoing Downloads (with statesDownload.STATE_LOADING
orDownload.STATE_QUEUED
) will be automatically paused.static final String
Use this as action inIntentFilter.addAction(String)
to receive messages that the device storage is sufficient to continue with downloadsstatic final int
The download path could not be updated due to the Download being in an invalid state.static final int
The download path could not be updated due to that the Download could not be found.static final int
The download path could not be updated due to an unknown error.static final int
The download path has been successfully updated.static final int
Error type that indicates a connectivity issue on the client devicestatic final int
Error type that indicates a DRM license fetching error.static final int
Error type for HTTP related download error.static final int
Generic error type for errors that could not be identified more specificallystatic final String
Use this as category inIntentFilter.addCategory(java.lang.String)
for filtering out the broadcasted downloader messagesstatic final String
Use this asIntent
key to indicate the download errorstatic final String
Use this asIntent
key to find the DRM error.static final String
Use this asIntent
key to find the http status error for errors of typeERROR_TYPE_HTTP_ERROR
.static final String
Use this asIntent
key to find the URL that caused the error for errors of typeERROR_TYPE_HTTP_ERROR
.static final String
Use this asIntent
key to find the error type.static final String
Use this asIntent
key to indicate the download Idstatic final String
static final String
Use this asIntent
key to find the result of the Download Path Update. -
Method Summary
-
Field Details
-
ERROR_TYPE_UNKNOWN_ERROR
public static final int ERROR_TYPE_UNKNOWN_ERRORGeneric error type for errors that could not be identified more specifically- See Also:
-
ERROR_TYPE_HTTP_ERROR
public static final int ERROR_TYPE_HTTP_ERRORError type for HTTP related download error. Errors for this type typically also carry the response status code- See Also:
-
ERROR_TYPE_CONNECTION_ERROR
public static final int ERROR_TYPE_CONNECTION_ERRORError type that indicates a connectivity issue on the client device- See Also:
-
ERROR_TYPE_DRM_ERROR
public static final int ERROR_TYPE_DRM_ERRORError type that indicates a DRM license fetching error. The DRM error can be accessed through theINTENT_DOWNLOAD_ERROR_DRM
key.- See Also:
-
INTENT_DOWNLOAD_CATEGORY
Use this as category inIntentFilter.addCategory(java.lang.String)
for filtering out the broadcasted downloader messages- See Also:
-
INTENT_DOWNLOAD_ID
Use this asIntent
key to indicate the download Id- See Also:
-
INTENT_DOWNLOAD_ERROR
Use this asIntent
key to indicate the download error- See Also:
-
INTENT_DOWNLOAD_ERROR_TYPE
Use this asIntent
key to find the error type. The value is anint
representing one of theERROR_*
constants in this class.- See Also:
-
INTENT_DOWNLOAD_ERROR_HTTP_STATUS
Use this asIntent
key to find the http status error for errors of typeERROR_TYPE_HTTP_ERROR
. The status code is reported as anint
. If the status code could not be identified, it will be set to-1
.- See Also:
-
INTENT_DOWNLOAD_ERROR_HTTP_URL
Use this asIntent
key to find the URL that caused the error for errors of typeERROR_TYPE_HTTP_ERROR
. The URL is reported as anString
.- See Also:
-
INTENT_DOWNLOAD_ERROR_DRM
Use this asIntent
key to find the DRM error. The value is anint
representing one of theERROR_*
constants inDrmTodayException
.- See Also:
-
ACTION_DOWNLOAD_STOPPED
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been stopped- See Also:
-
ACTION_DOWNLOAD_CREATED
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been created- See Also:
-
ACTION_DOWNLOAD_STARTED
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been started- See Also:
-
ACTION_DOWNLOAD_DELETED
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been deleted- See Also:
-
ACTION_DOWNLOAD_COMPLETED
Use this as action inIntentFilter.addAction(String)
to receive messages that a download has been completed- See Also:
-
ACTION_DOWNLOAD_NO_PENDING
Use this as action inIntentFilter.addAction(String)
to receive messages that the download queue has no started downloads- See Also:
-
ACTION_DOWNLOAD_ERROR
Use this as action inIntentFilter.addAction(String)
to receive messages that a download error occurred- See Also:
-
ACTION_DOWNLOAD_STORAGE_LOW
Use this as action inIntentFilter.addAction(String)
to receive messages that the storage is insufficient to continue with downloads If this action is fired all ongoing Downloads (with statesDownload.STATE_LOADING
orDownload.STATE_QUEUED
) will be automatically paused.- See Also:
-
ACTION_DOWNLOAD_STORAGE_OK
Use this as action inIntentFilter.addAction(String)
to receive messages that the device storage is sufficient to continue with downloads- See Also:
-
ACTION_DOWNLOAD_PROGRESS
Use this as action inIntentFilter.addAction(String)
to receive messages that progress was made on the current download- See Also:
-
ACTION_DOWNLOAD_PATH_UPDATE
Use this as action inIntentFilter.addAction(String)
to receive messages that the path for a download has been updated, or failed to.- See Also:
-
INTENT_DOWNLOAD_PATH_UPDATE_RESULT
Use this asIntent
key to find the result of the Download Path Update. The value is anint
representing one of theDOWNLOAD_UPTADE_PATH_RESULT_*
constants inMessageHandler
.- See Also:
-
INTENT_DOWNLOAD_PATH_UPDATE_ERROR
Use this asIntent
key to find theException
in case there's been an error while updating the download path. Will be null if the result isDOWNLOAD_UPDATE_PATH_RESULT_SUCCESS
.- See Also:
-
DOWNLOAD_UPDATE_PATH_RESULT_SUCCESS
public static final int DOWNLOAD_UPDATE_PATH_RESULT_SUCCESSThe download path has been successfully updated.- See Also:
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWN
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWNThe download path could not be updated due to an unknown error.- See Also:
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_NOT_FOUND
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_NOT_FOUNDThe download path could not be updated due to that the Download could not be found.- See Also:
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_INVALID_STATE
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_INVALID_STATEThe download path could not be updated due to the Download being in an invalid state.- See Also:
-
-
Method Details
-
handleMessage
- Specified by:
handleMessage
in interfaceHandler.Callback
-