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_PROGRESSACTION_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 SummaryFieldsModifier and TypeFieldDescriptionstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download has been completedstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download has been createdstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download has been deletedstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download error occurredstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that the download queue has no started downloadsstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that the path for a download has been updated, or failed to.static final StringUse this as action inIntentFilter.addAction(String)to receive messages that progress was made on the current downloadstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that the download service timed out.static final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download has been startedstatic final StringUse this as action inIntentFilter.addAction(String)to receive messages that a download has been stoppedstatic final StringUse 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 final StringUse this as action inIntentFilter.addAction(String)to receive messages that the device storage is sufficient to continue with downloadsstatic final intThe download path could not be updated due to the Download being in an invalid state.static final intThe download path could not be updated due to that the Download could not be found.static final intThe download path could not be updated due to an unknown error.static final intThe download path has been successfully updated.static final intError type that indicates a connectivity issue on the client devicestatic final intError type that indicates a DRM license fetching error.static final intError type for HTTP related download error.static final intGeneric error type for errors that could not be identified more specificallystatic final StringUse this as category inIntentFilter.addCategory(java.lang.String)for filtering out the broadcasted downloader messagesstatic final StringUse this asIntentkey to indicate the download errorstatic final StringUse this asIntentkey to find the DRM error.static final StringUse this asIntentkey to find the http status error for errors of typeERROR_TYPE_HTTP_ERROR.static final StringUse this asIntentkey to find the URL that caused the error for errors of typeERROR_TYPE_HTTP_ERROR.static final StringUse this asIntentkey to find the error type.static final StringUse this asIntentkey to indicate the download Idstatic final Stringstatic final StringUse this asIntentkey to find the result of the Download Path Update.
- 
Method Summary
- 
Field Details- 
ERROR_TYPE_UNKNOWN_ERRORpublic static final int ERROR_TYPE_UNKNOWN_ERRORGeneric error type for errors that could not be identified more specifically- See Also:
 
- 
ERROR_TYPE_HTTP_ERRORpublic 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_ERRORpublic static final int ERROR_TYPE_CONNECTION_ERRORError type that indicates a connectivity issue on the client device- See Also:
 
- 
ERROR_TYPE_DRM_ERRORpublic 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_DRMkey.- See Also:
 
- 
INTENT_DOWNLOAD_CATEGORYUse this as category inIntentFilter.addCategory(java.lang.String)for filtering out the broadcasted downloader messages- See Also:
 
- 
INTENT_DOWNLOAD_IDUse this asIntentkey to indicate the download Id- See Also:
 
- 
INTENT_DOWNLOAD_ERRORUse this asIntentkey to indicate the download error- See Also:
 
- 
INTENT_DOWNLOAD_ERROR_TYPEUse this asIntentkey to find the error type. The value is anintrepresenting one of theERROR_*constants in this class.- See Also:
 
- 
INTENT_DOWNLOAD_ERROR_HTTP_STATUSUse 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:
 
- 
INTENT_DOWNLOAD_ERROR_HTTP_URLUse 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:
 
- 
INTENT_DOWNLOAD_ERROR_DRMUse this asIntentkey to find the DRM error. The value is anintrepresenting one of theERROR_*constants inDrmTodayException.- See Also:
 
- 
ACTION_DOWNLOAD_STOPPEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been stopped- See Also:
 
- 
ACTION_DOWNLOAD_CREATEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been created- See Also:
 
- 
ACTION_DOWNLOAD_STARTEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been started- See Also:
 
- 
ACTION_DOWNLOAD_DELETEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been deleted- See Also:
 
- 
ACTION_DOWNLOAD_COMPLETEDUse this as action inIntentFilter.addAction(String)to receive messages that a download has been completed- See Also:
 
- 
ACTION_DOWNLOAD_NO_PENDINGUse this as action inIntentFilter.addAction(String)to receive messages that the download queue has no started downloads- See Also:
 
- 
ACTION_DOWNLOAD_ERRORUse this as action inIntentFilter.addAction(String)to receive messages that a download error occurred- See Also:
 
- 
ACTION_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.- See Also:
 
- 
ACTION_DOWNLOAD_STORAGE_OKUse this as action inIntentFilter.addAction(String)to receive messages that the device storage is sufficient to continue with downloads- See Also:
 
- 
ACTION_DOWNLOAD_PROGRESSUse this as action inIntentFilter.addAction(String)to receive messages that progress was made on the current download- See Also:
 
- 
ACTION_DOWNLOAD_PATH_UPDATEUse this as action inIntentFilter.addAction(String)to receive messages that the path for a download has been updated, or failed to.- See Also:
 
- 
ACTION_DOWNLOAD_SERVICE_TIMEOUTUse this as action inIntentFilter.addAction(String)to receive messages that the download service timed out.When targeting Android 15 (API 35) and higher, the system imposes time limits for background services of type dataSync, which the DownloadService uses. If this limit is hit the service will automatically pause any ongoing downloads and immediately stop itself. It is then the responsibility of the application to resume any paused downloads when the app returns to the foreground. - See Also:
 
- 
INTENT_DOWNLOAD_PATH_UPDATE_RESULTUse 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:
 
- 
INTENT_DOWNLOAD_PATH_UPDATE_ERRORUse 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:
 
- 
DOWNLOAD_UPDATE_PATH_RESULT_SUCCESSpublic static final int DOWNLOAD_UPDATE_PATH_RESULT_SUCCESSThe download path has been successfully updated.- See Also:
 
- 
DOWNLOAD_UPDATE_PATH_RESULT_ERROR_DOWNLOAD_UNKNOWNpublic 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_FOUNDpublic 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_STATEpublic 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:
- handleMessagein interface- Handler.Callback
 
 
-