Class MessageHandler
- java.lang.Object
-
- com.castlabs.sdk.downloader.MessageHandler
-
- All Implemented Interfaces:
Handler.Callback
public class MessageHandler extends Object implements Handler.Callback
The download message handler broadcasts downloader related messages:ACTION_DOWNLOAD_STOPPEDACTION_DOWNLOAD_CREATEDACTION_DOWNLOAD_STARTEDACTION_DOWNLOAD_DELETEDACTION_DOWNLOAD_COMPLETEDACTION_DOWNLOAD_NO_PENDINGACTION_DOWNLOAD_ERRORACTION_DOWNLOAD_STORAGE_LOWACTION_DOWNLOAD_STORAGE_OK
ACTION_DOWNLOAD_PROGRESS The following sample shows how to subscribe and receive the downloader messages:ACTION_DOWNLOAD_PATH_UPDATEIntentFilter 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_IDparameter, which is the download IDString. In addition, allACTION_DOWNLOAD_ERRORmessages contain theINTENT_DOWNLOAD_ERRORString, 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.
General connectivity issues are reported asINTENT_DOWNLOAD_ERROR_TYPEcontains the error type, which is one of theERROR_*constants of this class. Some of the error types might contains additional information. You can check for the http status code under theINTENT_DOWNLOAD_ERROR_HTTP_STATUSkey. The URL that caused the error can be checked withINTENT_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_ERRORwhen 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_ERRORif there was a problem while fetching the offline license. The underlying DRM error code can be queried through theINTENT_DOWNLOAD_ERROR_DRMkey, which will contain one of the values defined in the constants starting withERROR_*inDrmTodayException.
-
-
Field Summary
Fields Modifier and Type Field Description static StringACTION_DOWNLOAD_COMPLETEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been completedstatic StringACTION_DOWNLOAD_CREATEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been createdstatic StringACTION_DOWNLOAD_DELETEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been deletedstatic StringACTION_DOWNLOAD_ERRORUse this as action inIntentFilter.addAction(String)to receive messages that a download error occurredstatic StringACTION_DOWNLOAD_NO_PENDINGUse this as action inIntentFilter.addAction(String)to receive messages that the download queue has no started downloadsstatic StringACTION_DOWNLOAD_PATH_UPDATEUse this as action inIntentFilter.addAction(String)to receive messages that the path for a download has been updated, or failed to.static StringACTION_DOWNLOAD_PROGRESSUse this as action inIntentFilter.addAction(String)to receive messages that progress was made on the current downloadstatic StringACTION_DOWNLOAD_STARTEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been startedstatic StringACTION_DOWNLOAD_STOPPEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been stoppedstatic StringACTION_DOWNLOAD_STORAGE_LOWUse 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_LOADINGorDownload.STATE_QUEUED) will be automatically paused.static StringACTION_DOWNLOAD_STORAGE_OKUse this as action inIntentFilter.addAction(String)to receive messages that the device storage is sufficient to continue with downloadsstatic intDOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_INVALID_STATEThe download path could not be updated due to the Download being in an invalid state.static intDOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_NOT_FOUNDThe download path could not be updated due to that the Download could not be found.static intDOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWNThe download path could not be updated due to an unknown error.static intDOWNLOAD_UPDATE_PATH_RESULT_SUCCESSThe download path has been successfully updated.static intERROR_TYPE_CONNECTION_ERRORError type that indicates a connectivity issue on the client devicestatic intERROR_TYPE_DRM_ERRORError type that indicates a DRM license fetching error.static intERROR_TYPE_HTTP_ERRORError type for HTTP related download error.static intERROR_TYPE_UNKNOWN_ERRORGeneric error type for errors that could not be identified more specificallystatic StringINTENT_DOWNLOAD_CATEGORYUse this as category inIntentFilter.addCategory(java.lang.String)for filtering out the broadcasted downloader messagesstatic StringINTENT_DOWNLOAD_ERRORUse this asIntentkey to indicate the download errorstatic StringINTENT_DOWNLOAD_ERROR_DRMUse this asIntentkey to find the DRM error.static StringINTENT_DOWNLOAD_ERROR_HTTP_STATUSUse this asIntentkey to find the http status error for errors of typeERROR_TYPE_HTTP_ERROR.static StringINTENT_DOWNLOAD_ERROR_HTTP_URLUse this asIntentkey to find the URL that caused the error for errors of typeERROR_TYPE_HTTP_ERROR.static StringINTENT_DOWNLOAD_ERROR_TYPEUse this asIntentkey to find the error type.static StringINTENT_DOWNLOAD_IDUse this asIntentkey to indicate the download Idstatic StringINTENT_DOWNLOAD_PATH_UPDATE_ERRORstatic StringINTENT_DOWNLOAD_PATH_UPDATE_RESULTUse this asIntentkey to find the result of the Download Path Update.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhandleMessage(Message msg)
-
-
-
Field Detail
-
ERROR_TYPE_UNKNOWN_ERROR
public static final int ERROR_TYPE_UNKNOWN_ERROR
Generic error type for errors that could not be identified more specifically- See Also:
- Constant Field Values
-
ERROR_TYPE_HTTP_ERROR
public static final int ERROR_TYPE_HTTP_ERROR
Error type for HTTP related download error. Errors for this type typically also carry the response status code- See Also:
- Constant Field Values
-
ERROR_TYPE_CONNECTION_ERROR
public static final int ERROR_TYPE_CONNECTION_ERROR
Error type that indicates a connectivity issue on the client device- See Also:
- Constant Field Values
-
ERROR_TYPE_DRM_ERROR
public static final int ERROR_TYPE_DRM_ERROR
Error type that indicates a DRM license fetching error. The DRM error can be accessed through theINTENT_DOWNLOAD_ERROR_DRMkey.- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_CATEGORY
public static final String INTENT_DOWNLOAD_CATEGORY
Use this as category inIntentFilter.addCategory(java.lang.String)for filtering out the broadcasted downloader messages- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_ID
public static final String INTENT_DOWNLOAD_ID
Use this asIntentkey to indicate the download Id- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_ERROR
public static final String INTENT_DOWNLOAD_ERROR
Use this asIntentkey to indicate the download error- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_ERROR_TYPE
public static final String INTENT_DOWNLOAD_ERROR_TYPE
Use this asIntentkey to find the error type. The value is anintrepresenting one of theERROR_*constants in this class.- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_ERROR_HTTP_STATUS
public static final String INTENT_DOWNLOAD_ERROR_HTTP_STATUS
Use this asIntentkey 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:
- Constant Field Values
-
INTENT_DOWNLOAD_ERROR_HTTP_URL
public static final String INTENT_DOWNLOAD_ERROR_HTTP_URL
Use this asIntentkey to find the URL that caused the error for errors of typeERROR_TYPE_HTTP_ERROR. The URL is reported as anString.- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_ERROR_DRM
public static final String INTENT_DOWNLOAD_ERROR_DRM
Use this asIntentkey to find the DRM error. The value is anintrepresenting one of theERROR_*constants inDrmTodayException.- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_STOPPED
public static final String ACTION_DOWNLOAD_STOPPED
Use this as action inIntentFilter.addAction(String)to receive messages that a download has been stopped- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_CREATED
public static final String ACTION_DOWNLOAD_CREATED
Use this as action inIntentFilter.addAction(String)to receive messages that a download has been created- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_STARTED
public static final String ACTION_DOWNLOAD_STARTED
Use this as action inIntentFilter.addAction(String)to receive messages that a download has been started- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_DELETED
public static final String ACTION_DOWNLOAD_DELETED
Use this as action inIntentFilter.addAction(String)to receive messages that a download has been deleted- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_COMPLETED
public static final String ACTION_DOWNLOAD_COMPLETED
Use this as action inIntentFilter.addAction(String)to receive messages that a download has been completed- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_NO_PENDING
public static final String ACTION_DOWNLOAD_NO_PENDING
Use this as action inIntentFilter.addAction(String)to receive messages that the download queue has no started downloads- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_ERROR
public static final String ACTION_DOWNLOAD_ERROR
Use this as action inIntentFilter.addAction(String)to receive messages that a download error occurred- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_STORAGE_LOW
public static final String 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_LOADINGorDownload.STATE_QUEUED) will be automatically paused.- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_STORAGE_OK
public static final String 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:
- Constant Field Values
-
ACTION_DOWNLOAD_PROGRESS
public static final String ACTION_DOWNLOAD_PROGRESS
Use this as action inIntentFilter.addAction(String)to receive messages that progress was made on the current download- See Also:
- Constant Field Values
-
ACTION_DOWNLOAD_PATH_UPDATE
public static final String 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:
- Constant Field Values
-
INTENT_DOWNLOAD_PATH_UPDATE_RESULT
public static final String INTENT_DOWNLOAD_PATH_UPDATE_RESULT
Use this asIntentkey to find the result of the Download Path Update. The value is anintrepresenting one of theDOWNLOAD_UPTADE_PATH_RESULT_*constants inMessageHandler.- See Also:
- Constant Field Values
-
INTENT_DOWNLOAD_PATH_UPDATE_ERROR
public static final String INTENT_DOWNLOAD_PATH_UPDATE_ERROR
Use this asIntentkey to find theExceptionin case there's been an error while updating the download path. Will be null if the result isDOWNLOAD_UPDATE_PATH_RESULT_SUCCESS.- See Also:
- Constant Field Values
-
DOWNLOAD_UPDATE_PATH_RESULT_SUCCESS
public static final int DOWNLOAD_UPDATE_PATH_RESULT_SUCCESS
The download path has been successfully updated.- See Also:
- Constant Field Values
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWN
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWN
The download path could not be updated due to an unknown error.- See Also:
- Constant Field Values
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_NOT_FOUND
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_NOT_FOUND
The download path could not be updated due to that the Download could not be found.- See Also:
- Constant Field Values
-
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_INVALID_STATE
public static final int DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_INVALID_STATE
The download path could not be updated due to the Download being in an invalid state.- See Also:
- Constant Field Values
-
-
Method Detail
-
handleMessage
public boolean handleMessage(Message msg)
- Specified by:
handleMessagein interfaceHandler.Callback
-
-